惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
I
InfoQ
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
罗磊的独立博客

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno
Supabase Functions on Deno Deploy | Deno
2022-04-01 · via Deno

We’re excited to announce our partnership with Supabase in the launch of their new product, Supabase Functions, which allows you to deploy code globally on the edge within seconds. It’s built on top of our Deno Deploy infrastructure, which includes auto-scaling and auto-caching by default, so you can focus less on infrastructure and more on building product.

With Deno, Supabase Functions get first class TypeScript support, ESM style imports, out of the box security, and support for modern web APIs.

If you haven’t heard of Supabase before, it is an open source Firebase alternative, that provides backend services to create and deploy websites, services, and apps. The new Functions product joins an impressive suite of managed solutions, including database, storage, and a user management system.

Let’s take a look at how to get started.

Functions with Supabase

Getting started with Supabase Functions only takes minutes.

Install and setup the Supabase CLI

On Mac, you can use homebrew:

$ brew install supabase/tap/supabase

See other installation instructions.

Log into your Supabase CLI by grabbing an access token here and pasting it into the prompt that appears after this command:

Create a Supabase function

You can create a function with the subcommand functions:

$ supabase functions new hello

This will create a function stub supabase/functions/hello/index.ts, which will look like this:

import { serve } from "https://deno.land/std@0.140.0/http/server.ts";

console.log("Hello from Functions!");

serve(async (req) => {
  const { name } = await req.json();
  const data = {
    message: `Hello ${name}!`,
  };

  return new Response(
    JSON.stringify(data),
    { headers: { "Content-Type": "application/json" } },
  );
});

Execute the function locally

First, start Docker, then start the Supabase stack:

$ supabase start
Started local development setup.

         API URL: http://localhost:54321
          DB URL: postgresql://postgres:postgres@localhost:54322/postgres
      Studio URL: http://localhost:54323
    Inbucket URL: http://localhost:54324
        anon key: eyxxxxx
service_role key: eyzzzzz

Grab the anon key, because we’ll need to pass it in the headers to invoke the function.

Next, start the function watcher:

$ supabase functions serve hello

Note that supabase function serve has hot-reloading capabilities. It’ll restart the Deno server if there are any changes to your files.

Once the function is being served locally, you can execute it using curl. Replace ANON_KEY with the anon key from the supabase start output.

$ curl --location --request POST 'http://localhost:54321/functions/v1/' \
    --header 'Authorization: Bearer ANON_KEY' \
    --header 'Content-Type: application/json' \
    --data '{"name":"Functions"}'

You should receive the response {"message":"Hello Functions!"}.

Deploy the function

You can deploy the function directly from the CLI. First, you have to link a Supabase project. Head over to supabase.com and create a project.

Your Supabase project should have a URL structure like https://app.supabase.io/project/xyzabcxxxxxx. The alphabetical letters after /project/ is the project’s ref, which you’ll have to provide in the below command:

$ supabase link --ref xyzabcxxxxxx
Finished supabase link.

Then, deployment is as simple as:

$ supabase functions deploy hello
Bundling supabase/functions/hello
Deployed Function hello on project xyzabcxxxxxx.

Finally, execute the function in production. Note that the ANON_KEY here should be in the settings of your project on Supabase’s website.

curl --location --request POST 'https://PROJECT_REF.supabase.co/functions/' \
  --header 'Authorization: Bearer ANON_KEY' \
  --header 'Content-Type: application/json' \
  --data '{"name": "Functions"}'

You should receive the response {"message":"Hello Functions!"}.

For more information, see Supabase’s documentation.

What’s next?

We are huge advocates for making web development as easy and delightful as possible, and enabling Supabase developers to enhance their apps with edge functions deployed globally with Deno Deploy is a step in that direction. And with more developers using Deno and Deno Deploy, it’ll help us improve so that you can continue to have the best experience building and deploying products for your users.

Want to provide fast, easy, and global edge deployments for your users? Email us at deploy@deno.com.