mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
Netlify Edge Functions
This commit is contained in:
parent
613e211976
commit
a9fd7d5d13
4 changed files with 27 additions and 43 deletions
|
|
@ -18,6 +18,7 @@
|
|||
"@babel/core": "^7.21.0",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"@netlify/functions": "^1.4.0",
|
||||
"@netlify/remix-edge-adapter": "^1.0.0",
|
||||
"@remix-run/dev": "^1.13.0",
|
||||
"@remix-run/netlify": "^1.13.0",
|
||||
"@remix-run/node": "^1.13.0",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ specifiers:
|
|||
'@babel/core': ^7.21.0
|
||||
'@babel/preset-react': ^7.18.6
|
||||
'@netlify/functions': ^1.4.0
|
||||
'@netlify/remix-edge-adapter': ^1.0.0
|
||||
'@remix-run/dev': ^1.13.0
|
||||
'@remix-run/netlify': ^1.13.0
|
||||
'@remix-run/node': ^1.13.0
|
||||
|
|
@ -42,6 +43,7 @@ dependencies:
|
|||
'@babel/core': 7.21.0
|
||||
'@babel/preset-react': 7.18.6_@babel+core@7.21.0
|
||||
'@netlify/functions': 1.4.0
|
||||
'@netlify/remix-edge-adapter': 1.0.0
|
||||
'@remix-run/dev': 1.13.0_@remix-run+serve@1.13.0
|
||||
'@remix-run/netlify': 1.13.0_@netlify+functions@1.4.0
|
||||
'@remix-run/node': 1.13.0
|
||||
|
|
@ -1722,6 +1724,18 @@ packages:
|
|||
is-promise: 4.0.0
|
||||
dev: false
|
||||
|
||||
/@netlify/remix-edge-adapter/1.0.0:
|
||||
resolution: {integrity: sha512-NdTDRW8X/Iyh/ywHcf5H7HUkLoc/k2oxxOMIO5/rm0LHMN2bGFhbOxMBfi0PtFsa/Jn+efbNTkCM15JXoITzSw==}
|
||||
dependencies:
|
||||
'@netlify/remix-runtime': 1.0.0
|
||||
dev: false
|
||||
|
||||
/@netlify/remix-runtime/1.0.0:
|
||||
resolution: {integrity: sha512-w1nLlMABrW5uJoQc3eADWZ4wgnRqcqpNOQ+ZMQnoXSwukUGGN6JwGs3/BP+f/8F4CCy7sakbbF+akBmyKIKciQ==}
|
||||
dependencies:
|
||||
'@remix-run/server-runtime': 1.13.0
|
||||
dev: false
|
||||
|
||||
/@nicolo-ribaudo/eslint-scope-5-internals/5.1.1-v1:
|
||||
resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==}
|
||||
dependencies:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
const { config } = require("@netlify/remix-edge-adapter");
|
||||
/** @type {import('@remix-run/dev').AppConfig} */
|
||||
module.exports = {
|
||||
...config,
|
||||
appDirectory: "src",
|
||||
future: {
|
||||
unstable_postcss: true,
|
||||
|
|
@ -9,5 +11,5 @@ module.exports = {
|
|||
process.env.NETLIFY || process.env.NETLIFY_LOCAL
|
||||
? "./server.js"
|
||||
: undefined,
|
||||
serverBuildPath: ".netlify/functions-internal/server.js",
|
||||
// serverBuildPath: ".netlify/functions-internal/server.js",
|
||||
};
|
||||
|
|
|
|||
51
server.js
51
server.js
|
|
@ -1,47 +1,14 @@
|
|||
import { createRequestHandler } from "@remix-run/netlify";
|
||||
// Import path interpreted by the Remix compiler
|
||||
import * as build from "@remix-run/dev/server-build";
|
||||
import { createRequestHandler } from "@netlify/remix-edge-adapter";
|
||||
|
||||
/*
|
||||
* Returns a context object with at most 3 keys:
|
||||
* - `netlifyGraphToken`: raw authentication token to use with Netlify Graph
|
||||
* - `clientNetlifyGraphAccessToken`: For use with JWTs generated by
|
||||
* `netlify-graph-auth`.
|
||||
* - `netlifyGraphSignature`: a signature for subscription events. Will be
|
||||
* present if a secret is set.
|
||||
*/
|
||||
function getLoadContext(event, context) {
|
||||
let rawAuthorizationString;
|
||||
let netlifyGraphToken;
|
||||
|
||||
if (event.authlifyToken != null) {
|
||||
netlifyGraphToken = event.authlifyToken;
|
||||
}
|
||||
|
||||
const authHeader = event.headers["authorization"];
|
||||
const graphSignatureHeader = event.headers["x-netlify-graph-signature"];
|
||||
|
||||
if (authHeader != null && /Bearer /gi.test(authHeader)) {
|
||||
rawAuthorizationString = authHeader.split(" ")[1];
|
||||
}
|
||||
|
||||
const loadContext = {
|
||||
clientNetlifyGraphAccessToken: rawAuthorizationString,
|
||||
netlifyGraphToken: netlifyGraphToken,
|
||||
netlifyGraphSignature: graphSignatureHeader,
|
||||
};
|
||||
|
||||
// Remove keys with undefined values
|
||||
Object.keys(loadContext).forEach((key) => {
|
||||
if (loadContext[key] == null) {
|
||||
delete loadContext[key];
|
||||
}
|
||||
});
|
||||
|
||||
return loadContext;
|
||||
}
|
||||
|
||||
export const handler = createRequestHandler({
|
||||
export default createRequestHandler({
|
||||
build,
|
||||
getLoadContext,
|
||||
// process.env.NODE_ENV is provided by Remix at compile time
|
||||
mode: process.env.NODE_ENV,
|
||||
});
|
||||
|
||||
export const config = {
|
||||
cache: "manual",
|
||||
path: "/*",
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue