-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load edge functions bootstrap from module (#6496)
* feat: load edge functions bootstrap from module * chore: add test * refactor: update error logging * chore: update `@netlify/edge-functions`
- Loading branch information
1 parent
a6f0f45
commit bb2279f
Showing
8 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import { env } from 'process' | ||
|
||
const latestBootstrapURL = 'https://65f9b38dc160de0008d35515--edge.netlify.com/bootstrap/index-combined.ts' | ||
import { getURL } from '@netlify/edge-functions/version' | ||
|
||
export const getBootstrapURL = () => env.NETLIFY_EDGE_BOOTSTRAP || latestBootstrapURL | ||
import { warn } from '../../utils/command-helpers.js' | ||
|
||
export const FALLBACK_BOOTSTRAP_URL = 'https://edge.netlify.com/bootstrap/index-combined.ts' | ||
|
||
export const getBootstrapURL = async () => { | ||
if (env.NETLIFY_EDGE_BOOTSTRAP) { | ||
return env.NETLIFY_EDGE_BOOTSTRAP | ||
} | ||
|
||
try { | ||
return await getURL() | ||
} catch (error) { | ||
warn(`Could not load latest version of Edge Functions environment: ${(error as NodeJS.ErrnoException)?.message}`) | ||
|
||
// If there was an error getting the bootstrap URL from the module, let's | ||
// use the latest version of the bootstrap. This is not ideal, but better | ||
// than failing to serve requests with edge functions. | ||
return FALLBACK_BOOTSTRAP_URL | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { env } from 'process' | ||
|
||
import { describe, expect, test } from 'vitest' | ||
|
||
import { getBootstrapURL, FALLBACK_BOOTSTRAP_URL } from '../../../../dist/lib/edge-functions/bootstrap.js' | ||
|
||
describe('`getBootstrapURL()`', () => { | ||
test('Returns the URL in the `NETLIFY_EDGE_BOOTSTRAP` URL, if set', async () => { | ||
const mockBootstrapURL = 'https://edge.netlify/bootstrap.ts' | ||
|
||
env.NETLIFY_EDGE_BOOTSTRAP = mockBootstrapURL | ||
|
||
const bootstrapURL = await getBootstrapURL() | ||
|
||
delete env.NETLIFY_EDGE_BOOTSTRAP | ||
|
||
expect(bootstrapURL).toEqual(mockBootstrapURL) | ||
}) | ||
|
||
test('Returns a publicly accessible URL', async () => { | ||
const bootstrapURL = await getBootstrapURL() | ||
|
||
// We shouldn't get the fallback URL, because that means we couldn't get | ||
// the URL from the `@netlify/edge-functions` module. | ||
expect(bootstrapURL).not.toBe(FALLBACK_BOOTSTRAP_URL) | ||
|
||
const res = await fetch(bootstrapURL) | ||
|
||
expect(res.status).toBe(200) | ||
expect(res.headers.get('content-type').startsWith('application/typescript')).toBe(true) | ||
}) | ||
}) |
bb2279f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results
bb2279f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results