@openworkers/adapter-sveltekit 0.5.3 → 0.5.4
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.d.ts +10 -0
- package/dist/index.js +101176 -58
- package/dist/{function-worker.js → runtime/function-worker.js} +25 -8
- package/dist/{worker.js → runtime/worker.js} +9 -6
- package/dist/{lib → shims}/async-hooks.js +1 -1
- package/dist/{lib → shims}/node-fs.js +1 -1
- package/dist/{lib → shims}/node-path.js +1 -1
- package/dist/{lib → shims}/node-url.js +1 -1
- package/package.json +1 -1
- /package/dist/{lib → runtime}/cookies.js +0 -0
- /package/dist/{lib → runtime}/routing.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/function-worker.ts
|
|
1
|
+
// src/runtime/function-worker.ts
|
|
2
2
|
import * as handlers from "ENDPOINT";
|
|
3
3
|
var worker = {
|
|
4
4
|
async fetch(req, env, ctx) {
|
|
@@ -28,6 +28,7 @@ var worker = {
|
|
|
28
28
|
cookiesData = getCookies(req, url);
|
|
29
29
|
cookiesData.set_trailing_slash("ignore");
|
|
30
30
|
}
|
|
31
|
+
const noopSpan = {};
|
|
31
32
|
const event = {
|
|
32
33
|
fetch: globalThis.fetch.bind(globalThis),
|
|
33
34
|
request: req,
|
|
@@ -36,6 +37,11 @@ var worker = {
|
|
|
36
37
|
cookies: WITH_COOKIES && cookiesData?.cookies || void 0,
|
|
37
38
|
locals: {},
|
|
38
39
|
platform: { env, ctx },
|
|
40
|
+
route: { id: ROUTE_PATTERN },
|
|
41
|
+
isDataRequest: false,
|
|
42
|
+
isSubRequest: false,
|
|
43
|
+
isRemoteRequest: false,
|
|
44
|
+
tracing: { enabled: false, root: noopSpan, current: noopSpan },
|
|
39
45
|
getClientAddress() {
|
|
40
46
|
return req.headers.get("x-real-ip") ?? req.headers.get("x-forwarded-for") ?? "";
|
|
41
47
|
},
|
|
@@ -45,8 +51,8 @@ var worker = {
|
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
|
-
|
|
49
|
-
const response = await handler(
|
|
54
|
+
const resolve = async (resolvedEvent) => {
|
|
55
|
+
const response = await handler(resolvedEvent);
|
|
50
56
|
if (WITH_COOKIES && cookiesData?.new_cookies) {
|
|
51
57
|
const { addCookiesToHeaders } = await import("lib:cookies");
|
|
52
58
|
addCookiesToHeaders(response.headers, cookiesData.new_cookies.values());
|
|
@@ -55,6 +61,14 @@ var worker = {
|
|
|
55
61
|
response.headers.append(key, value);
|
|
56
62
|
}
|
|
57
63
|
return response;
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
if (WITH_HOOKS) {
|
|
67
|
+
const { handle } = await import("lib:hooks");
|
|
68
|
+
return await handle({ event, resolve });
|
|
69
|
+
} else {
|
|
70
|
+
return await resolve(event);
|
|
71
|
+
}
|
|
58
72
|
} catch (error) {
|
|
59
73
|
if (error?.status >= 300 && error?.status < 400 && error?.location) {
|
|
60
74
|
return new Response(null, {
|
|
@@ -63,16 +77,19 @@ var worker = {
|
|
|
63
77
|
});
|
|
64
78
|
}
|
|
65
79
|
if (error?.status && error?.body) {
|
|
66
|
-
return
|
|
80
|
+
return Response.json(error.body, {
|
|
67
81
|
status: error.status,
|
|
68
82
|
headers: { "Content-Type": "application/json" }
|
|
69
83
|
});
|
|
70
84
|
}
|
|
71
85
|
console.error(`[Function] Error in ${method} handler:`, error);
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
return Response.json(
|
|
87
|
+
{ error: "Internal Server Error" },
|
|
88
|
+
{
|
|
89
|
+
status: 500,
|
|
90
|
+
headers: { "Content-Type": "application/json" }
|
|
91
|
+
}
|
|
92
|
+
);
|
|
76
93
|
}
|
|
77
94
|
}
|
|
78
95
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// src/worker.ts
|
|
1
|
+
// src/runtime/worker.ts
|
|
2
2
|
import { Server, manifest, prerendered, base_path } from "SERVER";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var immutable = `${app_path}/immutable/`;
|
|
6
|
-
var version_file = `${app_path}/version.json`;
|
|
3
|
+
|
|
4
|
+
// src/shims/caches.ts
|
|
7
5
|
if (typeof caches === "undefined") {
|
|
8
6
|
const noopCache = {
|
|
9
7
|
match: async () => void 0,
|
|
@@ -16,6 +14,12 @@ if (typeof caches === "undefined") {
|
|
|
16
14
|
open: async () => noopCache
|
|
17
15
|
};
|
|
18
16
|
}
|
|
17
|
+
|
|
18
|
+
// src/runtime/worker.ts
|
|
19
|
+
var server = new Server(manifest);
|
|
20
|
+
var app_path = `/${manifest.appPath}`;
|
|
21
|
+
var immutable = `${app_path}/immutable/`;
|
|
22
|
+
var version_file = `${app_path}/version.json`;
|
|
19
23
|
var origin;
|
|
20
24
|
var initialized = server.init({
|
|
21
25
|
env: globalThis.env ?? {},
|
|
@@ -30,7 +34,6 @@ var initialized = server.init({
|
|
|
30
34
|
});
|
|
31
35
|
var worker = {
|
|
32
36
|
async fetch(req, env, ctx) {
|
|
33
|
-
globalThis.env = env;
|
|
34
37
|
const proto = req.headers.get("x-forwarded-proto");
|
|
35
38
|
if (proto && !req.url.startsWith(proto)) {
|
|
36
39
|
req = new Request(req.url.replace(/^http:/, `${proto}:`), req);
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|