@openworkers/adapter-sveltekit 0.5.5 → 0.5.6
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/dist/index.js +59 -0
- package/dist/runtime/page-worker.js +53 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -101419,6 +101419,65 @@ globalThis.process = globalThis.process || { env: { NODE_ENV: "production" } };`
|
|
|
101419
101419
|
builder.log.minor(` Generated function: ${routePattern} \u2192 ${workerFile}`);
|
|
101420
101420
|
}
|
|
101421
101421
|
}
|
|
101422
|
+
for (const route of builder.routes) {
|
|
101423
|
+
if (route.prerender === true) continue;
|
|
101424
|
+
if (route.page.methods.length === 0) continue;
|
|
101425
|
+
if (!route.id) continue;
|
|
101426
|
+
const workerName = route.id.replace(/\//g, "-").replace(/^-/, "") || "index";
|
|
101427
|
+
const workerFile = `functions/${workerName}.js`;
|
|
101428
|
+
const pageManifest = `${tmp}/manifest-${workerName}.js`;
|
|
101429
|
+
writeFileSync2(
|
|
101430
|
+
pageManifest,
|
|
101431
|
+
`export const manifest = ${builder.generateManifest({
|
|
101432
|
+
relativePath: path16.posix.relative(tmp, builder.getServerDirectory()),
|
|
101433
|
+
routes: [route]
|
|
101434
|
+
})};
|
|
101435
|
+
`
|
|
101436
|
+
);
|
|
101437
|
+
const pageEntry = `${tmp}/entry-${workerName}.js`;
|
|
101438
|
+
writeFileSync2(
|
|
101439
|
+
pageEntry,
|
|
101440
|
+
`import { Server } from '${serverPath}';
|
|
101441
|
+
import { manifest } from '${posixify(path16.resolve(pageManifest))}';
|
|
101442
|
+
export { Server, manifest };
|
|
101443
|
+
`
|
|
101444
|
+
);
|
|
101445
|
+
await build2({
|
|
101446
|
+
entryPoints: [`${files}/runtime/page-worker.js`],
|
|
101447
|
+
bundle: true,
|
|
101448
|
+
format: "esm",
|
|
101449
|
+
platform: "neutral",
|
|
101450
|
+
mainFields: ["module", "main"],
|
|
101451
|
+
outfile: `${dest}/${workerFile}`,
|
|
101452
|
+
alias: {
|
|
101453
|
+
SERVER: pageEntry,
|
|
101454
|
+
"node:async_hooks": `${shimsDir}/async-hooks.js`,
|
|
101455
|
+
...nodeCompat ? {
|
|
101456
|
+
path: `${shimsDir}/node-path.js`,
|
|
101457
|
+
"node:path": `${shimsDir}/node-path.js`,
|
|
101458
|
+
fs: `${shimsDir}/node-fs.js`,
|
|
101459
|
+
"node:fs": `${shimsDir}/node-fs.js`,
|
|
101460
|
+
url: `${shimsDir}/node-url.js`,
|
|
101461
|
+
"node:url": `${shimsDir}/node-url.js`
|
|
101462
|
+
} : {}
|
|
101463
|
+
},
|
|
101464
|
+
external: ["node:*"],
|
|
101465
|
+
minifySyntax: true,
|
|
101466
|
+
minifyWhitespace: true,
|
|
101467
|
+
minifyIdentifiers: true,
|
|
101468
|
+
treeShaking: true
|
|
101469
|
+
});
|
|
101470
|
+
const pattern = convertRouteToPattern(route.id);
|
|
101471
|
+
functions.push({
|
|
101472
|
+
pattern,
|
|
101473
|
+
worker: workerFile
|
|
101474
|
+
});
|
|
101475
|
+
functions.push({
|
|
101476
|
+
pattern: pattern + "/__data.json",
|
|
101477
|
+
worker: workerFile
|
|
101478
|
+
});
|
|
101479
|
+
builder.log.minor(` Generated page function: ${pattern} \u2192 ${workerFile}`);
|
|
101480
|
+
}
|
|
101422
101481
|
}
|
|
101423
101482
|
const routes = {
|
|
101424
101483
|
// Immutable assets (hashed filenames, cache forever)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/runtime/page-worker.ts
|
|
2
|
+
import { Server, manifest } from "SERVER";
|
|
3
|
+
|
|
4
|
+
// src/shims/caches.ts
|
|
5
|
+
if (typeof caches === "undefined") {
|
|
6
|
+
const noopCache = {
|
|
7
|
+
match: async () => void 0,
|
|
8
|
+
put: async () => {
|
|
9
|
+
},
|
|
10
|
+
delete: async () => false
|
|
11
|
+
};
|
|
12
|
+
globalThis.caches = {
|
|
13
|
+
default: noopCache,
|
|
14
|
+
open: async () => noopCache
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/runtime/page-worker.ts
|
|
19
|
+
var server = new Server(manifest);
|
|
20
|
+
var origin;
|
|
21
|
+
var initialized = server.init({
|
|
22
|
+
env: globalThis.env ?? {},
|
|
23
|
+
read: async (file) => {
|
|
24
|
+
const url = `${origin}/${file}`;
|
|
25
|
+
const response = await globalThis.env.ASSETS.fetch(url);
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new Error(`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`);
|
|
28
|
+
}
|
|
29
|
+
return response.body;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
var worker = {
|
|
33
|
+
async fetch(req, env, ctx) {
|
|
34
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
35
|
+
if (proto && !req.url.startsWith(proto)) {
|
|
36
|
+
req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
|
|
37
|
+
}
|
|
38
|
+
if (!origin) {
|
|
39
|
+
origin = new URL(req.url).origin;
|
|
40
|
+
}
|
|
41
|
+
await initialized;
|
|
42
|
+
return server.respond(req, {
|
|
43
|
+
platform: { env, ctx },
|
|
44
|
+
getClientAddress() {
|
|
45
|
+
return req.headers.get("x-real-ip") ?? req.headers.get("x-forwarded-for") ?? "";
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var page_worker_default = worker;
|
|
51
|
+
export {
|
|
52
|
+
page_worker_default as default
|
|
53
|
+
};
|