@fastly/remix-server-adapter 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# Remix Adapter for Fastly Compute
|
|
1
|
+
# Remix Adapter for Fastly Compute
|
|
2
2
|
|
|
3
|
-
An adapter that allows the Compute
|
|
4
|
-
package we have created is designed to be used with Fastly Compute
|
|
3
|
+
An adapter that allows the Compute JavaScript entry point program to start Remix. This adapter
|
|
4
|
+
package we have created is designed to be used with Fastly Compute, and currently uses
|
|
5
5
|
[`@fastly/compute-js-static-publish`](https://github.com/fastly/compute-js-static-publish)
|
|
6
6
|
behind the scenes to include resources into the Wasm package bundle.
|
|
7
7
|
|
|
@@ -8,7 +8,7 @@ import type { AppLoadContext, ServerBuild } from "@fastly/remix-server-runtime";
|
|
|
8
8
|
* You can think of this as an escape hatch that allows you to pass
|
|
9
9
|
* environment/platform-specific values through to your loader/action.
|
|
10
10
|
*/
|
|
11
|
-
export type GetLoadContextFunction = (event: FetchEvent) => AppLoadContext;
|
|
11
|
+
export type GetLoadContextFunction = (event: FetchEvent) => Promise<AppLoadContext> | AppLoadContext;
|
|
12
12
|
export type RequestHandler = ReturnType<typeof createRequestHandler>;
|
|
13
13
|
/**
|
|
14
14
|
* Generates a Response that would serve a static asset corresponding to the URL requested
|
|
@@ -19,7 +19,7 @@ export type RequestHandler = ReturnType<typeof createRequestHandler>;
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function handleAsset(event: FetchEvent, build: ServerBuild, server: PublisherServer): Promise<Response | null>;
|
|
21
21
|
/**
|
|
22
|
-
* Returns a request handler for the Fastly Compute
|
|
22
|
+
* Returns a request handler for the Fastly Compute runtime that serves the
|
|
23
23
|
* Remix SSR response.
|
|
24
24
|
*/
|
|
25
25
|
export declare function createRequestHandler({ build, getLoadContext, mode, }: {
|
|
@@ -28,7 +28,7 @@ export declare function createRequestHandler({ build, getLoadContext, mode, }: {
|
|
|
28
28
|
mode?: string;
|
|
29
29
|
}): (event: FetchEvent) => Promise<Response>;
|
|
30
30
|
/**
|
|
31
|
-
* Creates a simplified event handler that can be used on Fastly Compute
|
|
31
|
+
* Creates a simplified event handler that can be used on Fastly Compute.
|
|
32
32
|
* @param build { ServerBuild }
|
|
33
33
|
* @param getLoadContext { GetLoadContextFunction }
|
|
34
34
|
* @param serve { PublisherServer }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implementation.d.ts","sourceRoot":"","sources":["../../src/implementation.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhF;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"implementation.d.ts","sourceRoot":"","sources":["../../src/implementation.ts"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhF;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAErG,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAErE;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA2B1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,cAAc,EACd,IAAI,GACL,EAAE;IACD,KAAK,EAAE,WAAW,CAAC;IACnB,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,WAGsB,UAAU,uBAahC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,cAAc,EACd,MAAM,EACN,IAAI,GACL,EAAE;IACD,KAAK,EAAE,WAAW,CAAC;IACnB,cAAc,CAAC,EAAE,sBAAsB,CAAC;IACxC,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,WAiBgB,UAAU,UAgB1B"}
|
|
@@ -39,14 +39,14 @@ async function handleAsset(event, build, server) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.handleAsset = handleAsset;
|
|
41
41
|
/**
|
|
42
|
-
* Returns a request handler for the Fastly Compute
|
|
42
|
+
* Returns a request handler for the Fastly Compute runtime that serves the
|
|
43
43
|
* Remix SSR response.
|
|
44
44
|
*/
|
|
45
45
|
function createRequestHandler({ build, getLoadContext, mode, }) {
|
|
46
46
|
let handleRequest = (0, remix_server_runtime_1.createRequestHandler)(build, mode);
|
|
47
|
-
return (event) => {
|
|
47
|
+
return async (event) => {
|
|
48
48
|
var _a;
|
|
49
|
-
let loadContext = getLoadContext?.(event);
|
|
49
|
+
let loadContext = await getLoadContext?.(event);
|
|
50
50
|
// HACK: Until js-compute supports AbortSignal on Request
|
|
51
51
|
// we add a fake AbortSignal that doesn't actually abort
|
|
52
52
|
(_a = Request.prototype).signal ?? (_a.signal = {
|
|
@@ -59,7 +59,7 @@ function createRequestHandler({ build, getLoadContext, mode, }) {
|
|
|
59
59
|
}
|
|
60
60
|
exports.createRequestHandler = createRequestHandler;
|
|
61
61
|
/**
|
|
62
|
-
* Creates a simplified event handler that can be used on Fastly Compute
|
|
62
|
+
* Creates a simplified event handler that can be used on Fastly Compute.
|
|
63
63
|
* @param build { ServerBuild }
|
|
64
64
|
* @param getLoadContext { GetLoadContextFunction }
|
|
65
65
|
* @param serve { PublisherServer }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/implementation.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,uEAAiG;AAajG;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,KAAiB,EACjB,KAAkB,EAClB,MAAuB;IAGvB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IAEtD,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACvD,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,GAAqC,SAAS,CAAC;IAExD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;QAC1C,KAAK,GAAG,OAAO,CAAC;KACjB;SAAM;QACL,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnE,IAAI,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEpE,IAAI,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YACrC,iEAAiE;YACjE,KAAK,GAAG,UAAU,CAAC;SACpB;aAAM;YACL,0FAA0F;SAC3F;KACF;IAED,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC;AA/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KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;SACvC;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE;gBAC1C,KAAK,CAAC,WAAW,CACf,IAAI,QAAQ,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACtC,MAAM,EAAE,GAAG;iBACZ,CAAC,CACH,CAAC;gBACF,OAAO;aACR;YAED,KAAK,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;SACpE;IACH,CAAC,CAAC;AACJ,CAAC;AA3CD,gDA2CC","sourcesContent":["/*\n * Copyright Fastly, Inc.\n * Licensed under the MIT license. See LICENSE file for details.\n */\n\nimport type { PublisherServer } from \"@fastly/compute-js-static-publish\";\n\nimport type { AppLoadContext, ServerBuild } from \"@fastly/remix-server-runtime\";\nimport { createRequestHandler as createRemixRequestHandler } from \"@fastly/remix-server-runtime\";\n\n/**\n * A function that returns the value to use as `context` in route `loader` and\n * `action` functions.\n *\n * You can think of this as an escape hatch that allows you to pass\n * environment/platform-specific values through to your loader/action.\n */\nexport type GetLoadContextFunction = (event: FetchEvent) => Promise<AppLoadContext> | AppLoadContext;\n\nexport type RequestHandler = ReturnType<typeof createRequestHandler>;\n\n/**\n * Generates a Response that would serve a static asset corresponding to the URL requested\n * by the passed-in FetchEvent.\n * @param event { FetchEvent }\n * @param build { ServerBuild }\n * @param server { PublisherServer }\n */\nexport async function handleAsset(\n event: FetchEvent,\n build: ServerBuild,\n server: PublisherServer,\n): Promise<Response | null> {\n\n const request = event.request;\n const requestPathname = new URL(request.url).pathname;\n\n const asset = server.getMatchingAsset(requestPathname);\n if (asset == null) {\n return null;\n }\n\n let cache: 'extended' | 'never' | undefined = undefined;\n\n if (process.env.NODE_ENV === \"development\") {\n cache = 'never';\n } else {\n let assetpath = build.assets.url.split(\"/\").slice(0, -1).join(\"/\");\n let requestpath = requestPathname.split(\"/\").slice(0, -1).join(\"/\");\n\n if (requestpath.startsWith(assetpath)) {\n // Assets are hashed by Remix so are safe to cache in the browser\n cache = 'extended';\n } else {\n // Assets are not necessarily hashed in the request URL, so we cannot cache in the browser\n }\n }\n\n return server.serveAsset(event.request, asset, { cache });\n}\n\n/**\n * Returns a request handler for the Fastly Compute runtime that serves the\n * Remix SSR response.\n */\nexport function createRequestHandler({\n build,\n getLoadContext,\n mode,\n}: {\n build: ServerBuild;\n getLoadContext?: GetLoadContextFunction;\n mode?: string;\n}) {\n let handleRequest = createRemixRequestHandler(build, mode);\n\n return async (event: FetchEvent) => {\n let loadContext = await getLoadContext?.(event);\n\n // HACK: Until js-compute supports AbortSignal on Request\n // we add a fake AbortSignal that doesn't actually abort\n (Request.prototype as any).signal ??= {\n aborted: false,\n addEventListener: () => {},\n removeEventListener: () => {},\n };\n\n return handleRequest(event.request, loadContext);\n };\n}\n\n/**\n * Creates a simplified event handler that can be used on Fastly Compute.\n * @param build { ServerBuild }\n * @param getLoadContext { GetLoadContextFunction }\n * @param serve { PublisherServer }\n * @param mode { string }\n */\nexport function createEventHandler({\n build,\n getLoadContext,\n server,\n mode,\n}: {\n build: ServerBuild;\n getLoadContext?: GetLoadContextFunction;\n server: PublisherServer;\n mode?: string;\n}) {\n let handleRequest = createRequestHandler({\n build,\n getLoadContext,\n mode,\n });\n\n let handleEvent = async (event: FetchEvent) => {\n let response = await handleAsset(event, build, server);\n\n if (!response) {\n response = await handleRequest(event);\n }\n\n return response;\n };\n\n return (event: FetchEvent) => {\n try {\n event.respondWith(handleEvent(event));\n } catch (e: any) {\n if (process.env.NODE_ENV === \"development\") {\n event.respondWith(\n new Response(e.message || e.toString(), {\n status: 500,\n })\n );\n return;\n }\n\n event.respondWith(new Response(\"Internal Error\", { status: 500 }));\n }\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/remix-server-adapter",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "Remix Adapter for Fastly Compute
|
|
5
|
+
"description": "Remix Adapter for Fastly Compute",
|
|
6
6
|
"types": "./build/src/index.d.ts",
|
|
7
7
|
"main": "./build/src/index.js",
|
|
8
8
|
"exports": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fastly/compute-js-static-publish": "^5.0.0",
|
|
13
|
-
"@fastly/js-compute": "^
|
|
14
|
-
"@fastly/remix-server-runtime": "^2.0
|
|
13
|
+
"@fastly/js-compute": "^3.0.0",
|
|
14
|
+
"@fastly/remix-server-runtime": "^2.1.0"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"prepack": "npm run clean && npm run compile",
|