Skip to content

mlafeldt/netlify-edge-bootstrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

netlify-edge-bootstrap

This repo contains the "closed-source" bootstrap code used to initialize the environment of Netlify Edge Functions as well as the bundler code used for deploying them to Deno Deploy.

While the Edge Functions API is decently documented, I was still curious how Netlify actually integrates Deno as a JavaScript/TypeScript runtime behind the scenes. To that end, I extracted the code and created a playground that can run functions locally (similar to netlify dev).

I gathered all information contained here by reading the source code of Netlify's CLI & Edge Bundler and tinkering with deno vendor.

Usage

(Make sure to install Deno version 1.22 or higher first.)

Download current bootstrap code to src folder:

make bootstrap

Start playground webserver:

make playground

Send requests to playground:

curl -H 'x-nf-edge-functions: hello' -H 'x-nf-request-id: 1234' http://localhost:8000
Hello worldcurl -H 'x-nf-edge-functions: up,hello' -H 'x-nf-request-id: 1234' http://localhost:8000
HELLO WORLDcurl -H 'x-nf-edge-functions: up,skip,hello' -H 'x-nf-request-id: 1234' http://localhost:8000
HELLO WORLD

x-nf-edge-functions must contain a list of functions to be run in the given order. Function handlers are defined here.

Bundle functions like Netlify does before deploying to Deno Deploy:

make bundle

About

Learn how Netlify Edge Functions work under the hood

Topics

Resources

Stars

Watchers

Forks