@openworkers/adapter-sveltekit 0.4.3 → 0.5.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.
@@ -3,6 +3,10 @@ import * as handlers from "ENDPOINT";
3
3
  var worker = {
4
4
  async fetch(req, env, ctx) {
5
5
  globalThis.env = env;
6
+ const proto = req.headers.get("x-forwarded-proto");
7
+ if (proto && !req.url.startsWith(proto)) {
8
+ req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
9
+ }
6
10
  const method = req.method;
7
11
  const handler = handlers[method];
8
12
  if (!handler) {
@@ -52,6 +56,12 @@ var worker = {
52
56
  }
53
57
  return response;
54
58
  } catch (error) {
59
+ if (error?.status >= 300 && error?.status < 400 && error?.location) {
60
+ return new Response(null, {
61
+ status: error.status,
62
+ headers: { Location: error.location }
63
+ });
64
+ }
55
65
  if (error?.status && error?.body) {
56
66
  return new Response(JSON.stringify(error.body), {
57
67
  status: error.status,
package/dist/index.js CHANGED
@@ -203,9 +203,10 @@ function index_default(options = {}) {
203
203
  return {
204
204
  name,
205
205
  async adapt(builder) {
206
- const dest = options.out ?? "dist";
206
+ const dest = options.outDir ?? "build";
207
207
  const assetsDir = `${dest}/assets`;
208
208
  const functionsEnabled = options.functions ?? false;
209
+ const nodeCompat = options.nodeCompat ?? false;
209
210
  const files = fileURLToPath2(new URL(".", import.meta.url).href);
210
211
  const tmp = builder.getBuildDirectory("openworkers-tmp");
211
212
  builder.rimraf(dest);
@@ -240,24 +241,32 @@ export { Server, manifest, prerendered, base_path };
240
241
  `
241
242
  );
242
243
  const workerDest = `${dest}/_worker.js`;
243
- const libAsyncHooks = posixify(path2.resolve(files, "../src/lib/async-hooks.ts"));
244
+ const libDir = posixify(path2.resolve(files, "../src/lib"));
245
+ const libAsyncHooks = `${libDir}/async-hooks.ts`;
244
246
  await build2({
245
247
  entryPoints: [`${files}/worker.js`],
246
248
  bundle: true,
247
249
  format: "esm",
248
250
  platform: "neutral",
251
+ mainFields: ["module", "main"],
249
252
  outfile: workerDest,
250
253
  alias: {
251
254
  SERVER: entryPoint,
252
255
  MANIFEST: entryPoint,
253
- "node:async_hooks": libAsyncHooks
256
+ "node:async_hooks": libAsyncHooks,
257
+ ...nodeCompat ? {
258
+ "path": `${libDir}/node-path.ts`,
259
+ "fs": `${libDir}/node-fs.ts`,
260
+ "url": `${libDir}/node-url.ts`
261
+ } : {}
254
262
  },
255
263
  external: ["node:*"],
256
264
  minifySyntax: true,
257
265
  minifyIdentifiers: true,
258
266
  treeShaking: true,
259
267
  banner: {
260
- js: `// Generated by ${name} v${version} at ${(/* @__PURE__ */ new Date()).toISOString()}`
268
+ js: `// Generated by ${name} v${version} at ${(/* @__PURE__ */ new Date()).toISOString()}` + (nodeCompat ? `
269
+ globalThis.process = globalThis.process || { env: { NODE_ENV: "production" } };` : "")
261
270
  }
262
271
  });
263
272
  const functions = [];
package/dist/worker.js CHANGED
@@ -31,6 +31,10 @@ var initialized = server.init({
31
31
  var worker = {
32
32
  async fetch(req, env, ctx) {
33
33
  globalThis.env = env;
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
+ }
34
38
  if (!origin) {
35
39
  origin = new URL(req.url).origin;
36
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/adapter-sveltekit",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "SvelteKit adapter for OpenWorkers",
5
5
  "keywords": [
6
6
  "adapter",