Skip to content

feat: add support for edge functions#233

Merged
serhalp merged 38 commits into
mainfrom
feat/edge-functions
May 30, 2025
Merged

feat: add support for edge functions#233
serhalp merged 38 commits into
mainfrom
feat/edge-functions

Conversation

@eduardoboucas

Copy link
Copy Markdown
Member

No description provided.

@@ -0,0 +1,303 @@
<!DOCTYPE html>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied as is from the CLI.

import { fileURLToPath } from 'node:url'

const templatesPath = dirname(fileURLToPath(import.meta.url))
const functionErrorTemplatePath = resolve(templatesPath, '../src/templates/function-error.html')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was copied from the CLI. The only change I made was to hardcode the path to the function error template, as opposed to accepting it as an argument of renderFunctionErrorPage, as I didn't see a reason for that.

}

async start(port = 0) {
if (this.url) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change to make it possible to call start() multiple times without us starting multiple servers.

@@ -0,0 +1,3 @@
import { ulid } from 'ulid'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied as is from the CLI.

Comment thread packages/dev/src/main.ts

private async handleInEphemeralDirectory(request: Request, destPath: string) {
// Functions
const userFunctionsPath =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the initialisation of the handlers to the start() method so that we only have one instance of each handler per NetlifyDev instance.

Comment thread packages/dev/src/main.ts Outdated
}

this.#edgeFunctionsHandler = new EdgeFunctionsHandler({
bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to have this here. This needs to point to a specific version of the bootstrap, which is what the existing @netlify/edge-functions package (published from the bootstrap repo) does. We'll need to figure out a different setup here. For consistency, I've used @netlify/edge-functions for the new package in this monorepo, so perhaps we need to start publishing something like @netlify/edge-functions-bootstrap from the bootstrap repo and we add it as a dependency here.

Comment thread packages/dev/src/main.ts
@@ -0,0 +1,68 @@
type Cache = 'off' | 'manual'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was copied as is from the bootstrap repo.

Comment thread packages/dev/src/main.ts Outdated
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: ['*']
deno-version: ['v1.37.0', 'v1.44.4']

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to test with multiple versions of Deno.

Comment thread packages/dev/src/main.ts
Comment thread packages/dev/src/main.ts
}

if (this.#features.headers) {
this.#headersHandler = new HeadersHandler({

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhalp FYI, I moved the initialisation of all the handlers here, so I did the same to HeadersHandler.

@eduardoboucas eduardoboucas marked this pull request as ready for review May 29, 2025 13:30
@eduardoboucas eduardoboucas requested review from a team as code owners May 29, 2025 13:30
Comment thread eslint.config.js

const packagesPath = path.join(__dirname, 'packages')
const packages = await fs.readdir(packagesPath)
const packageIgnores = packages.map((name) => includeIgnoreFile(path.resolve(packagesPath, name, '.gitignore')))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awkward. As I mentioned to @serhalp, I think we should have each package defining its own lint step with its own ignore rules, etc.


export type Geolocation = Context['geo']

export const mockLocation: Geolocation = {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should incorporate the CLI logic that uses https://netlifind.netlify.app/ to provide a real geo-location object.

serhalp
serhalp previously approved these changes May 30, 2025

try {
await denoBridge.runInBackground(['run', ...denoFlags, denoRunPath, JSON.stringify(runOptions)], processRef, {
await denoBridge.runInBackground(['eval', ...denoFlags, script], processRef, {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread packages/edge-functions/dev/node/main.test.ts Outdated
Comment on lines +17 to +23
// Releasing version 1.2.3 of the `@netlify/edge-functions` module will
// make release-please create a GitHub release and corresponding tag of
// `v1.2.3`. Because the `edge` Netlify site is configured to build all
// branches, the tag will generate a `v1-2-3--edge.netlify.com` URL,
// which serves the bootstrap for this version. We're computing that
// URL here.
const branch = `v${version.split('.').join('-')}`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-authored-by: Philippe Serhal <philippe.serhal@netlify.com>
eduardoboucas and others added 7 commits May 30, 2025 16:51
serhalp
serhalp previously approved these changes May 30, 2025
@serhalp serhalp merged commit c80d77d into main May 30, 2025
7 checks passed
@serhalp serhalp deleted the feat/edge-functions branch May 30, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants