@fastly/remix-server-adapter 4.0.2 → 4.2.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
|
@@ -14,14 +14,14 @@ The simplest usage is the `createEventHandler` function.
|
|
|
14
14
|
This function needs to be passed the following parameters:
|
|
15
15
|
|
|
16
16
|
- `build`, obtained by loading `/build/index.js`
|
|
17
|
-
- `server`, obtained by calling `getServer()`, exported from
|
|
17
|
+
- `server`, obtained by calling `getServer()`, exported from `../static-publisher/statics.js`
|
|
18
18
|
|
|
19
|
-
> HINT:
|
|
19
|
+
> HINT: `../static-publisher/statics.js` is generated automatically by `@fastly/compute-js-static-publish`.
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
22
|
/// <reference types="@fastly/js-compute" />
|
|
23
23
|
import { createEventHandler } from '@fastly/remix-server-adapter';
|
|
24
|
-
import { moduleAssets, getServer } from '
|
|
24
|
+
import { moduleAssets, getServer } from '../static-publisher/statics.js';
|
|
25
25
|
|
|
26
26
|
/** @type {import('@remix-run/server-runtime').ServerBuild} */
|
|
27
27
|
const build = moduleAssets.getAsset('/build/index.js').getStaticModule();
|
|
@@ -38,7 +38,7 @@ you may use the lower-level `createRequestHandler` and `handleAsset` functions:
|
|
|
38
38
|
```js
|
|
39
39
|
/// <reference types="@fastly/js-compute" />
|
|
40
40
|
import { createRequestHandler, handleAsset } from '@fastly/remix-server-adapter';
|
|
41
|
-
import { moduleAssets, getServer } from '
|
|
41
|
+
import { moduleAssets, getServer } from '../static-publisher/statics.js';
|
|
42
42
|
|
|
43
43
|
/** @type {import('@remix-run/server-runtime').ServerBuild} */
|
|
44
44
|
const build = moduleAssets.getAsset('/build/index.js').getStaticModule();
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/// <reference types="@fastly/js-compute" />
|
|
2
2
|
import type { PublisherServer } from "@fastly/compute-js-static-publish";
|
|
3
3
|
import type { AppLoadContext, ServerBuild } from "@fastly/remix-server-runtime";
|
|
4
|
+
export type LoadContext = {
|
|
5
|
+
request: Request;
|
|
6
|
+
fastly: {
|
|
7
|
+
client: ClientInfo;
|
|
8
|
+
server: ServerInfo;
|
|
9
|
+
waitUntil(promise: Promise<any>): void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* A function that returns the value to use as `context` in route `loader` and
|
|
6
14
|
* `action` functions.
|
|
@@ -8,7 +16,7 @@ import type { AppLoadContext, ServerBuild } from "@fastly/remix-server-runtime";
|
|
|
8
16
|
* You can think of this as an escape hatch that allows you to pass
|
|
9
17
|
* environment/platform-specific values through to your loader/action.
|
|
10
18
|
*/
|
|
11
|
-
export type GetLoadContextFunction = (event: FetchEvent) => Promise<AppLoadContext> | AppLoadContext;
|
|
19
|
+
export type GetLoadContextFunction = (event: FetchEvent, context: LoadContext) => Promise<AppLoadContext> | AppLoadContext;
|
|
12
20
|
export type RequestHandler = (event: FetchEvent) => Promise<Response>;
|
|
13
21
|
/**
|
|
14
22
|
* Returns a request handler for the Fastly Compute runtime that serves the
|
|
@@ -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,CACnC,KAAK,EAAE,UAAU,
|
|
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,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE;QACN,MAAM,EAAE,UAAU,CAAC;QACnB,MAAM,EAAE,UAAU,CAAC;QACnB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;KACxC,CAAC;CACH,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,WAAW,KACjB,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtE;;;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,GAAG,cAAc,CA0BjB;AAED;;;;;;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;;;;;;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"}
|
|
@@ -11,10 +11,20 @@ const remix_server_runtime_1 = require("@fastly/remix-server-runtime");
|
|
|
11
11
|
* Remix SSR response.
|
|
12
12
|
*/
|
|
13
13
|
function createRequestHandler({ build, getLoadContext, mode, }) {
|
|
14
|
-
|
|
14
|
+
const handleRequest = (0, remix_server_runtime_1.createRequestHandler)(build, mode);
|
|
15
15
|
return async (event) => {
|
|
16
16
|
var _a;
|
|
17
|
-
|
|
17
|
+
const context = {
|
|
18
|
+
request: event.request,
|
|
19
|
+
fastly: {
|
|
20
|
+
client: event.client,
|
|
21
|
+
server: event.server,
|
|
22
|
+
waitUntil: event.waitUntil.bind(event),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const loadContext = getLoadContext != null ?
|
|
26
|
+
await getLoadContext(event, context) :
|
|
27
|
+
context;
|
|
18
28
|
// HACK: Until js-compute supports AbortSignal on Request
|
|
19
29
|
// we add a fake AbortSignal that doesn't actually abort
|
|
20
30
|
(_a = Request.prototype).signal ?? (_a.signal = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/implementation.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,uEAAiG;
|
|
1
|
+
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/implementation.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,uEAAiG;AAyBjG;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,cAAc,EACd,IAAI,GAKL;IACC,MAAM,aAAa,GAAG,IAAA,2CAAyB,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAE7D,OAAO,KAAK,EAAE,KAAiB,EAAE,EAAE;;QACjC,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE;gBACN,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;aACvC;SACF,CAAC;QACF,MAAM,WAAW,GAAmB,cAAc,IAAI,IAAI,CAAC,CAAC;YAC1D,MAAM,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;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ICENSE 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\nexport type LoadContext = {\n request: Request,\n fastly: {\n client: ClientInfo,\n server: ServerInfo,\n waitUntil(promise: Promise<any>): void;\n },\n};\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 = (\n event: FetchEvent,\n context: LoadContext,\n) => Promise<AppLoadContext> | AppLoadContext;\n\nexport type RequestHandler = (event: FetchEvent) => Promise<Response>;\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}): RequestHandler {\n const handleRequest = createRemixRequestHandler(build, mode);\n\n return async (event: FetchEvent) => {\n const context = {\n request: event.request,\n fastly: {\n client: event.client,\n server: event.server,\n waitUntil: event.waitUntil.bind(event),\n },\n };\n const loadContext: AppLoadContext = getLoadContext != null ?\n await getLoadContext(event, context) :\n context;\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 * 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 * 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/remix-server-adapter",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Remix Adapter for Fastly Compute",
|
|
6
6
|
"types": "./build/src/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fastly/compute-js-static-publish": "^6.0.0",
|
|
13
|
-
"@fastly/js-compute": "^3.
|
|
13
|
+
"@fastly/js-compute": "^3.33.2",
|
|
14
14
|
"@fastly/remix-server-runtime": "^4.0.0"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|