-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add metadata and
onError
to edge functions (#5584)
* feat: add metadata and `onError` to edge functions * refactor: move `getFeatureFlagsHeader` to separate file * refactor: move `getInvocationMetadataHeader` function --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f437d30
commit 1311734
Showing
5 changed files
with
132 additions
and
12 deletions.
There are no files selected for viewing
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,5 @@ | ||
import { env } from 'process' | ||
|
||
const latestBootstrapURL = 'https://64109c4552d9020008b9dadc--edge.netlify.com/bootstrap/index-combined.ts' | ||
const latestBootstrapURL = 'https://6419767d9dc968000848742a--edge.netlify.com/bootstrap/index-combined.ts' | ||
|
||
export const getBootstrapURL = () => env.NETLIFY_EDGE_BOOTSTRAP || latestBootstrapURL |
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,11 +1,36 @@ | ||
const headers = { | ||
// @ts-check | ||
import { Buffer } from 'buffer' | ||
|
||
export const headers = { | ||
FeatureFlags: 'x-nf-feature-flags', | ||
ForwardedHost: 'x-forwarded-host', | ||
Functions: 'x-nf-edge-functions', | ||
InvocationMetadata: 'x-nf-edge-functions-metadata', | ||
Geo: 'x-nf-geo', | ||
Passthrough: 'x-nf-passthrough', | ||
IP: 'x-nf-client-connection-ip', | ||
Site: 'X-NF-Site-Info', | ||
DebugLogging: 'x-nf-debug-logging', | ||
} | ||
|
||
export default headers | ||
/** | ||
* Takes an array of feature flags and produces a Base64-encoded JSON object | ||
* that the bootstrap layer can understand. | ||
* | ||
* @param {Array<string>} featureFlags | ||
* @returns {string} | ||
*/ | ||
export const getFeatureFlagsHeader = (featureFlags) => { | ||
const featureFlagsObject = featureFlags.reduce((acc, flagName) => ({ ...acc, [flagName]: true }), {}) | ||
|
||
return Buffer.from(JSON.stringify(featureFlagsObject)).toString('base64') | ||
} | ||
|
||
/** | ||
* Takes the invocation metadata object and produces a Base64-encoded JSON | ||
* object that the bootstrap layer can understand. | ||
* | ||
* @param {object} metadata | ||
* @returns {string} | ||
*/ | ||
export const getInvocationMetadataHeader = (metadata) => Buffer.from(JSON.stringify(metadata)).toString('base64') |
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
1311734
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