@tschk/moonshine-deploy-cloudflare 0.3.2 → 0.3.3
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/package.json +7 -7
- package/src/index.ts +17 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tschk/moonshine-deploy-cloudflare",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"test": "bun test"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@tschk/moonshine-adapter-conformance": "^0.3.
|
|
19
|
-
"@tschk/moonshine-compiler": "^0.3.
|
|
20
|
-
"@tschk/moonshine-framework": "^0.3.
|
|
21
|
-
"@tschk/moonshine-react": "^0.3.
|
|
22
|
-
"@tschk/moonshine-router": "^0.3.
|
|
23
|
-
"@tschk/moonshine-server": "^0.3.
|
|
18
|
+
"@tschk/moonshine-adapter-conformance": "^0.3.3",
|
|
19
|
+
"@tschk/moonshine-compiler": "^0.3.3",
|
|
20
|
+
"@tschk/moonshine-framework": "^0.3.3",
|
|
21
|
+
"@tschk/moonshine-react": "^0.3.3",
|
|
22
|
+
"@tschk/moonshine-router": "^0.3.3",
|
|
23
|
+
"@tschk/moonshine-server": "^0.3.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/bun": "1.3.14",
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { copyFile, mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createRequestHandler,
|
|
5
|
+
tryServeStatic,
|
|
6
|
+
type RouteModule,
|
|
7
|
+
} from "@tschk/moonshine-server";
|
|
4
8
|
import { matchRoutes, createRouteGraph } from "@tschk/moonshine-router";
|
|
5
|
-
import { reactRenderer } from "@tschk/moonshine-react";
|
|
9
|
+
import { reactRenderer, registerRouteModules } from "@tschk/moonshine-react";
|
|
6
10
|
import type {
|
|
7
11
|
DeploymentAdapter,
|
|
8
12
|
MoonshineManifest,
|
|
@@ -25,6 +29,7 @@ export async function cloudflareFetch(
|
|
|
25
29
|
env: CloudflareEnv,
|
|
26
30
|
ctx: CloudflareContext,
|
|
27
31
|
manifest: MoonshineManifest,
|
|
32
|
+
modules: Record<string, RouteModule> = {},
|
|
28
33
|
): Promise<Response> {
|
|
29
34
|
const url = new URL(request.url);
|
|
30
35
|
const pathname = url.pathname.replace(/\/+$/, "") || "/";
|
|
@@ -40,7 +45,12 @@ export async function cloudflareFetch(
|
|
|
40
45
|
|
|
41
46
|
const graph = createRouteGraph(manifest.routes);
|
|
42
47
|
const match = matchRoutes(graph, pathname);
|
|
43
|
-
|
|
48
|
+
registerRouteModules(modules);
|
|
49
|
+
const handler = createRequestHandler({
|
|
50
|
+
manifest,
|
|
51
|
+
modules,
|
|
52
|
+
renderer: reactRenderer,
|
|
53
|
+
});
|
|
44
54
|
const cache =
|
|
45
55
|
typeof caches !== "undefined"
|
|
46
56
|
? (caches as { default?: Cache }).default
|
|
@@ -173,14 +183,17 @@ export const cloudflareAdapter: DeploymentAdapter = {
|
|
|
173
183
|
);
|
|
174
184
|
await copyAssets(manifest.assets, outDir);
|
|
175
185
|
|
|
186
|
+
// The module map must be a static import: Workers cannot resolve the
|
|
187
|
+
// dynamic `import(route.file)` the renderer would otherwise fall back to.
|
|
176
188
|
const serverEntry = `import cloudflareFetch from "@tschk/moonshine-deploy-cloudflare";
|
|
177
189
|
import manifest from "./manifest.json" with { type: "json" };
|
|
190
|
+
import { modules } from "./dist/server.js";
|
|
178
191
|
|
|
179
192
|
type Env = { ASSETS?: { fetch: (request: Request) => Promise<Response> } };
|
|
180
193
|
|
|
181
194
|
export default {
|
|
182
195
|
async fetch(request: Request, env: Env, ctx: { waitUntil: (promise: Promise<unknown>) => void }) {
|
|
183
|
-
return cloudflareFetch(request, env, ctx, manifest);
|
|
196
|
+
return cloudflareFetch(request, env, ctx, manifest, modules);
|
|
184
197
|
},
|
|
185
198
|
};
|
|
186
199
|
`;
|