Skip to content

feat: add support for edge functions#233

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

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

Conversation

@eduardoboucas
Copy link
Member

No description provided.

@@ -0,0 +1,303 @@
<!DOCTYPE html>
Copy link
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
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
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
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.


private async handleInEphemeralDirectory(request: Request, destPath: string) {
// Functions
const userFunctionsPath =
Copy link
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.

}

this.#edgeFunctionsHandler = new EdgeFunctionsHandler({
bootstrapURL: 'https://edge.netlify.com/bootstrap/index-combined.ts',
Copy link
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.

@@ -0,0 +1,68 @@
type Cache = 'off' | 'manual'
Copy link
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.

matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: ['*']
deno-version: ['v1.37.0', 'v1.44.4']
Copy link
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.

}

if (this.#features.headers) {
this.#headersHandler = new HeadersHandler({
Copy link
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

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
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
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
Member

Choose a reason for hiding this comment

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

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
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