@celsoft/coordinator 0.0.0 → 0.1.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/CHANGELOG.md +11 -0
- package/README.md +107 -0
- package/THIRD_PARTY_NOTICES.md +2005 -0
- package/agents/console.md +20 -0
- package/agents/free.md +110 -0
- package/build/0-JP6XL6LB.js +17 -0
- package/build/1-A52YZWNS.js +17 -0
- package/build/2-CLH2NM6F.js +32 -0
- package/build/3-4N467IB6.js +45 -0
- package/build/4-WL5H4LUW.js +29 -0
- package/build/_layout.svelte-KPUSX7LQ.js +27 -0
- package/build/_page.svelte-22H56UR6.js +7972 -0
- package/build/_page.svelte-CVWUNRQC.js +135 -0
- package/build/_page.svelte-LTZXBHMT.js +57 -0
- package/build/_server.ts-3KVBYN6P.js +20 -0
- package/build/_server.ts-3POPKVEM.js +47 -0
- package/build/_server.ts-5735T2V5.js +31 -0
- package/build/_server.ts-5VXGNWV2.js +38 -0
- package/build/_server.ts-645KP7WP.js +42 -0
- package/build/_server.ts-A3AA24Z2.js +28 -0
- package/build/_server.ts-CITUOEM6.js +58 -0
- package/build/_server.ts-I7HMTPOA.js +25 -0
- package/build/_server.ts-M5BQ4LLX.js +30 -0
- package/build/_server.ts-OB4O27HF.js +683 -0
- package/build/_server.ts-OJT7HE7M.js +15 -0
- package/build/_server.ts-OYGWVLZM.js +12 -0
- package/build/_server.ts-T75UVMQP.js +38 -0
- package/build/_server.ts-WYZYNHUZ.js +28 -0
- package/build/_server.ts-Z26EB47B.js +486 -0
- package/build/chunk-4CIG53L5.js +33 -0
- package/build/chunk-BJTJS3XY.js +338 -0
- package/build/chunk-F2CNWJZM.js +14 -0
- package/build/chunk-HGYE3UTU.js +416 -0
- package/build/chunk-KAYW2W7H.js +1311 -0
- package/build/chunk-LFP3UPCM.js +10 -0
- package/build/chunk-M44JEFEH.js +62 -0
- package/build/chunk-MC5AGLMY.js +39 -0
- package/build/chunk-NCZ77J5E.js +19798 -0
- package/build/chunk-NVNLDPUJ.js +2122 -0
- package/build/chunk-PDCON4KS.js +494 -0
- package/build/chunk-Q4OQNY5M.js +25 -0
- package/build/chunk-QCUOR2U5.js +75 -0
- package/build/chunk-R6RYZZWA.js +46 -0
- package/build/chunk-SOJTASZC.js +51 -0
- package/build/chunk-SU26PJVX.js +410 -0
- package/build/chunk-U5BSBG4R.js +506 -0
- package/build/chunk-UEKOZGRO.js +37 -0
- package/build/chunk-W6EFUWJ2.js +9 -0
- package/build/chunk-WOPREK6Q.js +117 -0
- package/build/chunk-WWJ3F4QS.js +127 -0
- package/build/chunk-ZGZJEEE3.js +1091 -0
- package/build/client/_app/immutable/assets/0.BGa5ZNDM.css +1 -0
- package/build/client/_app/immutable/chunks/BUrrLYDt.js +2 -0
- package/build/client/_app/immutable/chunks/BgFr_EyZ.js +4 -0
- package/build/client/_app/immutable/chunks/Bjy-W4x2.js +82 -0
- package/build/client/_app/immutable/chunks/C8qZab0y.js +56 -0
- package/build/client/_app/immutable/chunks/C90fLsA5.js +4 -0
- package/build/client/_app/immutable/chunks/CRzLMJPS.js +1 -0
- package/build/client/_app/immutable/chunks/DLT1iIlz.js +2 -0
- package/build/client/_app/immutable/chunks/pIrVVOVY.js +2 -0
- package/build/client/_app/immutable/entry/app.0DERehLW.js +3 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js +2 -0
- package/build/client/_app/immutable/entry/start.B7srFiqh.js +3 -0
- package/build/client/_app/immutable/nodes/0.aD9vJoxR.js +2 -0
- package/build/client/_app/immutable/nodes/1.Br4FL91i.js +2 -0
- package/build/client/_app/immutable/nodes/2.vl6OYfu3.js +8 -0
- package/build/client/_app/immutable/nodes/3.VYqJOLAF.js +2 -0
- package/build/client/_app/immutable/nodes/4.jF9UVlFN.js +2 -0
- package/build/client/_app/version.json +1 -0
- package/build/client/apple-touch-icon.png +0 -0
- package/build/client/favicon.ico +0 -0
- package/build/client/favicon.svg +48 -0
- package/build/client/icon-192.png +0 -0
- package/build/client/icon-512.png +0 -0
- package/build/client/icon-maskable-512.png +0 -0
- package/build/client/icon.svg +44 -0
- package/build/client/manifest.webmanifest +15 -0
- package/build/error.svelte-JXZDY65F.js +51 -0
- package/build/handler.js +716 -0
- package/build/hooks.server-34IMHRKC.js +43 -0
- package/build/instance-NP3FJIWW.js +2967 -0
- package/client/client.mjs +28 -0
- package/client/hooks.mjs +7 -0
- package/client/register.mjs +5 -0
- package/dist/cli.js +62826 -0
- package/dist/port.js +36691 -0
- package/package.json +20 -1
- package/skills/agents/.claude-plugin/plugin.json +5 -0
- package/skills/agents/hooks/hooks.json +1 -0
- package/skills/agents/hooks/register.ts +57 -0
- package/skills/agents/skills/bus-work/SKILL.md +66 -0
- package/skills/agents/skills/plan/SKILL.md +98 -0
- package/skills/console/.claude-plugin/plugin.json +5 -0
- package/skills/console/hooks/hooks.json +1 -0
- package/skills/console/hooks/register.ts +10 -0
- package/skills/console/skills/bus/SKILL.md +61 -0
- package/skills/default/.claude-plugin/plugin.json +5 -0
- package/skills/default/skills/git-workflow/SKILL.md +294 -0
- package/skills/default/skills/git-workflow/mise-tasks/_lib.sh +107 -0
- package/skills/default/skills/git-workflow/mise-tasks/clone +36 -0
- package/skills/default/skills/git-workflow/mise-tasks/repo-list +8 -0
- package/skills/default/skills/git-workflow/mise-tasks/unpushed +26 -0
- package/skills/default/skills/git-workflow/mise-tasks/worktree-add +60 -0
- package/skills/default/skills/github/SKILL.md +208 -0
- package/skills/default/skills/github/scripts/gh-org +196 -0
- package/skills/default/skills/plan-page/SKILL.md +300 -0
- package/skills/default/skills/plan-page/assets/index.html +854 -0
- package/skills/default/skills/plan-page/scripts/inline +46 -0
- package/skills/default/skills/plan-page/scripts/stage +26 -0
- package/skills/default/skills/secrets/SKILL.md +134 -0
- package/skills/default/skills/secrets/scripts/secrets-check +87 -0
- package/skills/default/skills/writing-style/SKILL.md +45 -0
- package/skills/extra/.claude-plugin/plugin.json +5 -0
- package/skills/extra/skills/artifacts/SKILL.md +52 -0
- package/skills/extra/skills/github-actions/SKILL.md +78 -0
- package/skills/extra/skills/github-actions/scan +32 -0
- package/skills/extra/skills/markdown-review/SKILL.md +70 -0
- package/skills/extra/skills/markdown-review/assets/index.html +201 -0
- package/skills/extra/skills/markdown-review/scripts/stage +36 -0
- package/skills/extra/skills/mise-usage/SKILL.md +155 -0
- package/skills/extra/skills/plugin-authoring/SKILL.md +317 -0
- package/skills/extra/skills/project-conventions/SKILL.md +64 -0
- package/skills/extra/skills/questions/SKILL.md +156 -0
- package/skills/extra/skills/questions/assets/index.html +376 -0
- package/skills/extra/skills/questions/scripts/stage +26 -0
- package/skills/extra/skills/serve/SKILL.md +165 -0
- package/skills/extra/skills/serve/scripts/serve +268 -0
- package/skills/extra/skills/serve/scripts/server.py +345 -0
- package/skills/extra/skills/skill-dependencies/SKILL.md +65 -0
- package/skills/extra/skills/skill-maintenance/SKILL.md +101 -0
- package/skills/extra/skills/ticketing/SKILL.md +125 -0
|
@@ -0,0 +1,2967 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
BODY_DEPENDENT_METHODS,
|
|
4
|
+
ENDPOINT_METHODS,
|
|
5
|
+
INVALIDATED_PARAM,
|
|
6
|
+
IN_WEBCONTAINER,
|
|
7
|
+
PAGE_METHODS,
|
|
8
|
+
REROUTED_URL_HEADER,
|
|
9
|
+
TRAILING_SLASH_PARAM,
|
|
10
|
+
action_json_redirect,
|
|
11
|
+
add_data_suffix,
|
|
12
|
+
add_resolution_suffix,
|
|
13
|
+
app_dir,
|
|
14
|
+
assets,
|
|
15
|
+
base64_encode,
|
|
16
|
+
collect_remote_data,
|
|
17
|
+
decode_pathname,
|
|
18
|
+
disable_search,
|
|
19
|
+
disallow_on_server,
|
|
20
|
+
encoders,
|
|
21
|
+
fetch_cache_url,
|
|
22
|
+
find_route,
|
|
23
|
+
get_hooks,
|
|
24
|
+
get_node_type,
|
|
25
|
+
get_remote_action,
|
|
26
|
+
get_remote_id,
|
|
27
|
+
get_status,
|
|
28
|
+
handle_action_json_request,
|
|
29
|
+
handle_action_request,
|
|
30
|
+
handle_error_and_jsonify,
|
|
31
|
+
handle_remote_call,
|
|
32
|
+
handle_remote_form_post,
|
|
33
|
+
has_custom_transporters,
|
|
34
|
+
has_data_suffix,
|
|
35
|
+
has_prerendered_path,
|
|
36
|
+
has_resolution_suffix,
|
|
37
|
+
hooks,
|
|
38
|
+
init_transport,
|
|
39
|
+
invalid_export,
|
|
40
|
+
invalid_export_location,
|
|
41
|
+
is_action_json_request,
|
|
42
|
+
is_action_request,
|
|
43
|
+
is_form_content_type,
|
|
44
|
+
make_trackable,
|
|
45
|
+
manifest,
|
|
46
|
+
method_not_allowed,
|
|
47
|
+
negotiate,
|
|
48
|
+
noop,
|
|
49
|
+
normalize_error,
|
|
50
|
+
normalize_path,
|
|
51
|
+
once,
|
|
52
|
+
options,
|
|
53
|
+
read_implementation,
|
|
54
|
+
redirect_response,
|
|
55
|
+
relative_pathname,
|
|
56
|
+
resolve,
|
|
57
|
+
serialize_uses,
|
|
58
|
+
set_hooks,
|
|
59
|
+
stream_text,
|
|
60
|
+
stringify$1,
|
|
61
|
+
strip_data_suffix,
|
|
62
|
+
strip_resolution_suffix,
|
|
63
|
+
text_encoder,
|
|
64
|
+
throw_devalue_error,
|
|
65
|
+
uneval as uneval2,
|
|
66
|
+
uneval_action_response,
|
|
67
|
+
with_version_header
|
|
68
|
+
} from "./chunk-NVNLDPUJ.js";
|
|
69
|
+
import {
|
|
70
|
+
Redirect,
|
|
71
|
+
SvelteKitError,
|
|
72
|
+
isRedirect,
|
|
73
|
+
merge_tracing,
|
|
74
|
+
otel,
|
|
75
|
+
record_span,
|
|
76
|
+
text,
|
|
77
|
+
with_request_store
|
|
78
|
+
} from "./chunk-SU26PJVX.js";
|
|
79
|
+
import {
|
|
80
|
+
capture_error,
|
|
81
|
+
client_address_unsupported,
|
|
82
|
+
cookies_serialize_before_route,
|
|
83
|
+
cookies_set_after_response,
|
|
84
|
+
csp_report_only_missing_report,
|
|
85
|
+
endpoint_invalid_response,
|
|
86
|
+
header_already_set,
|
|
87
|
+
load_fetch_cors,
|
|
88
|
+
load_promise_not_serializable,
|
|
89
|
+
load_response_header_not_serialized,
|
|
90
|
+
prerender_actions,
|
|
91
|
+
prerender_endpoint_methods,
|
|
92
|
+
prerender_endpoint_not_prerenderable,
|
|
93
|
+
prerender_nonce,
|
|
94
|
+
prerender_template_nonce,
|
|
95
|
+
set_headers_after_response,
|
|
96
|
+
set_headers_cookie
|
|
97
|
+
} from "./chunk-WWJ3F4QS.js";
|
|
98
|
+
import {
|
|
99
|
+
derived,
|
|
100
|
+
escape_html,
|
|
101
|
+
render
|
|
102
|
+
} from "./chunk-KAYW2W7H.js";
|
|
103
|
+
import {
|
|
104
|
+
uneval
|
|
105
|
+
} from "./chunk-U5BSBG4R.js";
|
|
106
|
+
import "./chunk-LFP3UPCM.js";
|
|
107
|
+
|
|
108
|
+
// build/server/chunks/config.js
|
|
109
|
+
var explicit_public_env = {};
|
|
110
|
+
var rendered_env = {};
|
|
111
|
+
function set_env(env) {
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// build/server/chunks/instance.js
|
|
115
|
+
async function render_endpoint(event, state, mod) {
|
|
116
|
+
const method = event.request.method;
|
|
117
|
+
let handler = mod[method] || mod.fallback;
|
|
118
|
+
if (method === "HEAD" && !mod.HEAD && mod.GET) handler = mod.GET;
|
|
119
|
+
if (!handler) return method_not_allowed(mod, method);
|
|
120
|
+
const prerender = mod.prerender ?? state.prerender_default;
|
|
121
|
+
if (prerender && (mod.fallback || BODY_DEPENDENT_METHODS.some((method2) => mod[method2]))) prerender_endpoint_methods({
|
|
122
|
+
methods: BODY_DEPENDENT_METHODS.join(", "),
|
|
123
|
+
id: event.route.id
|
|
124
|
+
});
|
|
125
|
+
if (state.prerendering && !state.prerendering.inside_reroute && !prerender) {
|
|
126
|
+
if (state.depth > 0) prerender_endpoint_not_prerenderable({ id: event.route.id });
|
|
127
|
+
else return new Response(void 0, { status: 204 });
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const response = await record_span({
|
|
131
|
+
name: "sveltekit.endpoint",
|
|
132
|
+
attributes: {
|
|
133
|
+
"http.route": event.route.id || "unknown",
|
|
134
|
+
"http.method": method
|
|
135
|
+
},
|
|
136
|
+
fn: async (current) => {
|
|
137
|
+
const traced_event = merge_tracing(event, current);
|
|
138
|
+
return with_request_store({
|
|
139
|
+
event: traced_event,
|
|
140
|
+
state
|
|
141
|
+
}, () => handler(traced_event));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
if (!(response instanceof Response)) endpoint_invalid_response({ path: event.url.pathname });
|
|
145
|
+
if (state.prerendering && (!state.prerendering.inside_reroute || prerender)) {
|
|
146
|
+
const cloned = new Response(response.clone().body, {
|
|
147
|
+
status: response.status,
|
|
148
|
+
statusText: response.statusText,
|
|
149
|
+
headers: new Headers(response.headers)
|
|
150
|
+
});
|
|
151
|
+
cloned.headers.set("x-sveltekit-prerender", String(prerender));
|
|
152
|
+
if (state.prerendering.inside_reroute && prerender) {
|
|
153
|
+
cloned.headers.set("x-sveltekit-routeid", encodeURI(event.route.id));
|
|
154
|
+
state.prerendering.dependencies.set(event.url.pathname, {
|
|
155
|
+
response: cloned,
|
|
156
|
+
body: null
|
|
157
|
+
});
|
|
158
|
+
} else return cloned;
|
|
159
|
+
}
|
|
160
|
+
return response;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
if (e instanceof Redirect) return new Response(void 0, {
|
|
163
|
+
status: e.status,
|
|
164
|
+
headers: { location: e.location }
|
|
165
|
+
});
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function is_endpoint_request(event) {
|
|
170
|
+
const { method, headers: headers2 } = event.request;
|
|
171
|
+
if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) return true;
|
|
172
|
+
if (method === "POST" && headers2.get("x-sveltekit-action") === "true") return false;
|
|
173
|
+
const accept = event.request.headers.get("accept") ?? "*/*";
|
|
174
|
+
return negotiate(accept, ["*", "text/html"]) !== "text/html";
|
|
175
|
+
}
|
|
176
|
+
function compact(arr) {
|
|
177
|
+
return arr.filter(
|
|
178
|
+
/** @returns {val is NonNullable<T>} */
|
|
179
|
+
(val) => val != null
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
var ROUTES_PREFIX = "/routes";
|
|
183
|
+
function route_id_resolution_pathname(route_id) {
|
|
184
|
+
return add_resolution_suffix(`/${app_dir}${ROUTES_PREFIX}${route_id === "/" ? "" : route_id}`);
|
|
185
|
+
}
|
|
186
|
+
function is_route_id_resolution_path(pathname) {
|
|
187
|
+
const prefix = `/${app_dir}${ROUTES_PREFIX}`;
|
|
188
|
+
return pathname === prefix || pathname.startsWith(prefix + "/");
|
|
189
|
+
}
|
|
190
|
+
function extract_route_id(pathname) {
|
|
191
|
+
return pathname.slice(`/_app${ROUTES_PREFIX}`.length) || "/";
|
|
192
|
+
}
|
|
193
|
+
function build_error_chain(branch, errors, load) {
|
|
194
|
+
const chain = [void 0];
|
|
195
|
+
let last_idx = -1;
|
|
196
|
+
for (let i = 1; i < branch.length; i += 1) {
|
|
197
|
+
if (!branch[i]) continue;
|
|
198
|
+
let j = i - 1;
|
|
199
|
+
while (j > last_idx + 1 && errors[j] == null) j -= 1;
|
|
200
|
+
last_idx = j;
|
|
201
|
+
const error = errors[j];
|
|
202
|
+
chain.push(error == null ? void 0 : load(error)?.catch(() => void 0));
|
|
203
|
+
}
|
|
204
|
+
return Promise.all(chain);
|
|
205
|
+
}
|
|
206
|
+
function* nearest_error_pages(i, branch, errors) {
|
|
207
|
+
while (i--) {
|
|
208
|
+
const error = errors[i];
|
|
209
|
+
if (error != null) {
|
|
210
|
+
let j = i;
|
|
211
|
+
while (!branch[j]) j -= 1;
|
|
212
|
+
yield {
|
|
213
|
+
error,
|
|
214
|
+
idx: j + 1
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function create_async_iterator() {
|
|
220
|
+
let resolved = -1;
|
|
221
|
+
const deferred = [];
|
|
222
|
+
return {
|
|
223
|
+
async *iterate(transform = (x) => x) {
|
|
224
|
+
for (let i = 0; i < deferred.length; i += 1) yield transform(await deferred[i].promise);
|
|
225
|
+
},
|
|
226
|
+
add: (promise) => {
|
|
227
|
+
const next = Promise.withResolvers();
|
|
228
|
+
next.promise.catch(noop);
|
|
229
|
+
deferred.push(next);
|
|
230
|
+
promise.then((value) => {
|
|
231
|
+
deferred[++resolved].resolve(value);
|
|
232
|
+
}, (error) => {
|
|
233
|
+
deferred[++resolved].reject(error);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function server_data_serializer(event, state) {
|
|
239
|
+
let promise_id = 1;
|
|
240
|
+
let max_nodes = -1;
|
|
241
|
+
const iterator = create_async_iterator();
|
|
242
|
+
const global = "__sveltekit_1rxnxzs";
|
|
243
|
+
function get_replacer(index) {
|
|
244
|
+
return function replacer(thing) {
|
|
245
|
+
if (typeof thing?.then === "function") {
|
|
246
|
+
const id = promise_id++;
|
|
247
|
+
const promise = thing.then(
|
|
248
|
+
/** @param {any} data */
|
|
249
|
+
(data) => ({ data })
|
|
250
|
+
).catch(
|
|
251
|
+
/** @param {any} error */
|
|
252
|
+
async (error) => ({ error: await handle_error_and_jsonify(event, state, error) })
|
|
253
|
+
).then(
|
|
254
|
+
/**
|
|
255
|
+
* @param {{data: any; error: any}} result
|
|
256
|
+
*/
|
|
257
|
+
async ({ data, error }) => {
|
|
258
|
+
let str;
|
|
259
|
+
try {
|
|
260
|
+
str = uneval(error ? [, error] : [data], replacer);
|
|
261
|
+
} catch (serialization_error) {
|
|
262
|
+
error = await handle_error_and_jsonify(event, state, capture_error(() => load_promise_not_serializable({ id: event.route.id }, { cause: serialization_error })));
|
|
263
|
+
str = uneval([, error], replacer);
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
index,
|
|
267
|
+
str: `${global}.resolve(${id}, ${str.includes("app.decode") ? `(app) => ${str}` : `() => ${str}`})`
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
iterator.add(promise);
|
|
272
|
+
return `${global}.defer(${id})`;
|
|
273
|
+
} else for (const key in encoders) {
|
|
274
|
+
const encoded = encoders[key](thing);
|
|
275
|
+
if (encoded) return `app.decode('${key}', ${uneval(encoded, replacer)})`;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const strings = [];
|
|
280
|
+
return {
|
|
281
|
+
set_max_nodes(i) {
|
|
282
|
+
max_nodes = i;
|
|
283
|
+
},
|
|
284
|
+
add_node(i, node) {
|
|
285
|
+
try {
|
|
286
|
+
if (!node) {
|
|
287
|
+
strings[i] = "null";
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const payload2 = {
|
|
291
|
+
type: "data",
|
|
292
|
+
data: node.data,
|
|
293
|
+
uses: serialize_uses(node)
|
|
294
|
+
};
|
|
295
|
+
if (node.slash) payload2.slash = node.slash;
|
|
296
|
+
strings[i] = uneval(payload2, get_replacer(i));
|
|
297
|
+
} catch (error) {
|
|
298
|
+
error.path = error.path.slice(1);
|
|
299
|
+
throw_devalue_error(event, error);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
get_data(csp) {
|
|
303
|
+
const open = `<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>`;
|
|
304
|
+
const close = `</script>
|
|
305
|
+
`;
|
|
306
|
+
return {
|
|
307
|
+
data: `[${compact(max_nodes > -1 ? strings.slice(0, max_nodes) : strings).join(",")}]`,
|
|
308
|
+
chunks: promise_id > 1 ? iterator.iterate(({ index, str }) => {
|
|
309
|
+
if (max_nodes > -1 && index >= max_nodes) return "";
|
|
310
|
+
return open + str + close;
|
|
311
|
+
}) : null
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function server_data_serializer_json(event, state) {
|
|
317
|
+
let promise_id = 1;
|
|
318
|
+
const iterator = create_async_iterator();
|
|
319
|
+
const reducers = {
|
|
320
|
+
...encoders,
|
|
321
|
+
/** @param {any} thing */
|
|
322
|
+
Promise: (thing) => {
|
|
323
|
+
if (typeof thing?.then !== "function") return;
|
|
324
|
+
const id = promise_id++;
|
|
325
|
+
let key = "data";
|
|
326
|
+
const promise = thing.catch(
|
|
327
|
+
/** @param {any} error */
|
|
328
|
+
async (error) => {
|
|
329
|
+
key = "error";
|
|
330
|
+
return handle_error_and_jsonify(event, state, error);
|
|
331
|
+
}
|
|
332
|
+
).then(
|
|
333
|
+
/** @param {any} value */
|
|
334
|
+
async (value) => {
|
|
335
|
+
let str;
|
|
336
|
+
try {
|
|
337
|
+
str = stringify$1(value, reducers);
|
|
338
|
+
} catch (serialization_error) {
|
|
339
|
+
const error = await handle_error_and_jsonify(event, state, capture_error(() => load_promise_not_serializable({ id: event.route.id }, { cause: serialization_error })));
|
|
340
|
+
key = "error";
|
|
341
|
+
str = stringify$1(error, reducers);
|
|
342
|
+
}
|
|
343
|
+
return `{"type":"chunk","id":${id},"${key}":${str}}
|
|
344
|
+
`;
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
iterator.add(promise);
|
|
348
|
+
return id;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const strings = [];
|
|
352
|
+
return {
|
|
353
|
+
add_node(i, node) {
|
|
354
|
+
try {
|
|
355
|
+
if (!node) {
|
|
356
|
+
strings[i] = "null";
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (node.type === "error" || node.type === "skip") {
|
|
360
|
+
strings[i] = JSON.stringify(node);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
strings[i] = `{"type":"data","data":${stringify$1(node.data, reducers)},"uses":${JSON.stringify(serialize_uses(node))}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
error.path = "data" + error.path;
|
|
366
|
+
throw_devalue_error(event, error);
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
get_data() {
|
|
370
|
+
return {
|
|
371
|
+
data: `{"type":"data","nodes":[${strings.join(",")}]}
|
|
372
|
+
`,
|
|
373
|
+
chunks: promise_id > 1 ? iterator.iterate() : null
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
var NULL_BODY_STATUS = [
|
|
379
|
+
101,
|
|
380
|
+
103,
|
|
381
|
+
204,
|
|
382
|
+
205,
|
|
383
|
+
304
|
|
384
|
+
];
|
|
385
|
+
async function load_server_data({ event, state, node, parent }) {
|
|
386
|
+
if (!node?.server) return null;
|
|
387
|
+
let is_tracking = true;
|
|
388
|
+
const uses = {
|
|
389
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
390
|
+
params: /* @__PURE__ */ new Set(),
|
|
391
|
+
parent: false,
|
|
392
|
+
route: false,
|
|
393
|
+
url: false,
|
|
394
|
+
search_params: /* @__PURE__ */ new Set()
|
|
395
|
+
};
|
|
396
|
+
const load = node.server.load;
|
|
397
|
+
const slash = node.server.trailingSlash;
|
|
398
|
+
if (!load) return {
|
|
399
|
+
type: "data",
|
|
400
|
+
data: null,
|
|
401
|
+
uses,
|
|
402
|
+
slash
|
|
403
|
+
};
|
|
404
|
+
const url = make_trackable(event.url, () => {
|
|
405
|
+
if (is_tracking) uses.url = true;
|
|
406
|
+
}, (param) => {
|
|
407
|
+
if (is_tracking) uses.search_params.add(param);
|
|
408
|
+
});
|
|
409
|
+
if (state.prerendering || state.prerender_default === true) disable_search(url);
|
|
410
|
+
return {
|
|
411
|
+
type: "data",
|
|
412
|
+
data: await record_span({
|
|
413
|
+
name: "sveltekit.load",
|
|
414
|
+
attributes: {
|
|
415
|
+
"sveltekit.load.node_id": node.server_id || "unknown",
|
|
416
|
+
"sveltekit.load.node_type": get_node_type(node.server_id),
|
|
417
|
+
"sveltekit.load.environment": "server",
|
|
418
|
+
"http.route": event.route.id || "unknown"
|
|
419
|
+
},
|
|
420
|
+
fn: async (current) => {
|
|
421
|
+
const traced_event = merge_tracing(event, current);
|
|
422
|
+
return await with_request_store({
|
|
423
|
+
event: traced_event,
|
|
424
|
+
state
|
|
425
|
+
}, () => load.call(null, {
|
|
426
|
+
...traced_event,
|
|
427
|
+
fetch: (info, init2) => {
|
|
428
|
+
new URL(info instanceof Request ? info.url : info, event.url);
|
|
429
|
+
return event.fetch(info, init2);
|
|
430
|
+
},
|
|
431
|
+
/** @param {string[]} deps */
|
|
432
|
+
depends: (...deps) => {
|
|
433
|
+
for (const dep of deps) {
|
|
434
|
+
const { href } = new URL(dep, event.url);
|
|
435
|
+
uses.dependencies.add(href);
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
params: new Proxy(event.params, { get: (target, key) => {
|
|
439
|
+
if (is_tracking) uses.params.add(key);
|
|
440
|
+
return target[key];
|
|
441
|
+
} }),
|
|
442
|
+
parent: async () => {
|
|
443
|
+
if (is_tracking) uses.parent = true;
|
|
444
|
+
return parent();
|
|
445
|
+
},
|
|
446
|
+
route: new Proxy(event.route, { get: (target, key) => {
|
|
447
|
+
if (is_tracking) uses.route = true;
|
|
448
|
+
return target[key];
|
|
449
|
+
} }),
|
|
450
|
+
url,
|
|
451
|
+
untrack(fn) {
|
|
452
|
+
is_tracking = false;
|
|
453
|
+
try {
|
|
454
|
+
return fn();
|
|
455
|
+
} finally {
|
|
456
|
+
is_tracking = true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}));
|
|
460
|
+
}
|
|
461
|
+
}) ?? null,
|
|
462
|
+
uses,
|
|
463
|
+
slash
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
async function load_data({ event, state, fetched, node, parent, server_data_promise, resolve_opts, csr }) {
|
|
467
|
+
const server_data_node = await server_data_promise;
|
|
468
|
+
const load = node?.universal?.load;
|
|
469
|
+
if (!load) return server_data_node?.data ?? null;
|
|
470
|
+
return await record_span({
|
|
471
|
+
name: "sveltekit.load",
|
|
472
|
+
attributes: {
|
|
473
|
+
"sveltekit.load.node_id": node.universal_id || "unknown",
|
|
474
|
+
"sveltekit.load.node_type": get_node_type(node.universal_id),
|
|
475
|
+
"sveltekit.load.environment": "server",
|
|
476
|
+
"http.route": event.route.id || "unknown"
|
|
477
|
+
},
|
|
478
|
+
fn: async (current) => {
|
|
479
|
+
const traced_event = merge_tracing(event, current);
|
|
480
|
+
return await with_request_store({
|
|
481
|
+
event: traced_event,
|
|
482
|
+
state
|
|
483
|
+
}, () => load.call(null, {
|
|
484
|
+
url: event.url,
|
|
485
|
+
params: event.params,
|
|
486
|
+
data: server_data_node?.data ?? null,
|
|
487
|
+
route: event.route,
|
|
488
|
+
fetch: create_universal_fetch(event, state.prerendering, fetched, csr, resolve_opts),
|
|
489
|
+
setHeaders: event.setHeaders,
|
|
490
|
+
depends: noop,
|
|
491
|
+
parent,
|
|
492
|
+
untrack: (fn) => fn(),
|
|
493
|
+
tracing: traced_event.tracing
|
|
494
|
+
}));
|
|
495
|
+
}
|
|
496
|
+
}) ?? null;
|
|
497
|
+
}
|
|
498
|
+
function create_universal_fetch(event, prerendering, fetched, csr, resolve_opts) {
|
|
499
|
+
const universal_fetch = async (input, init2) => {
|
|
500
|
+
const cloned_body = input instanceof Request && input.body ? input.clone().body : null;
|
|
501
|
+
const cloned_headers = input instanceof Request && [...input.headers].length ? new Headers(input.headers) : init2?.headers;
|
|
502
|
+
let response = await event.fetch(input, init2);
|
|
503
|
+
const url = new URL(input instanceof Request ? input.url : input, event.url);
|
|
504
|
+
const same_origin = url.origin === event.url.origin;
|
|
505
|
+
let dependency;
|
|
506
|
+
if (same_origin) {
|
|
507
|
+
if (prerendering) {
|
|
508
|
+
dependency = {
|
|
509
|
+
response,
|
|
510
|
+
body: null
|
|
511
|
+
};
|
|
512
|
+
prerendering.dependencies.set(url.pathname, dependency);
|
|
513
|
+
}
|
|
514
|
+
} else if (url.protocol === "https:" || url.protocol === "http:") {
|
|
515
|
+
if ((input instanceof Request ? input.mode : init2?.mode ?? "cors") === "no-cors") response = new Response("", {
|
|
516
|
+
status: response.status,
|
|
517
|
+
statusText: response.statusText,
|
|
518
|
+
headers: response.headers
|
|
519
|
+
});
|
|
520
|
+
else {
|
|
521
|
+
const acao = response.headers.get("access-control-allow-origin");
|
|
522
|
+
if (!acao || acao !== event.url.origin && acao !== "*") load_fetch_cors({ reason: acao ? "Incorrect" : "No" });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
let teed_body;
|
|
526
|
+
const proxy = new Proxy(response, { get(response2, key, receiver) {
|
|
527
|
+
async function push_fetched(body, is_b64) {
|
|
528
|
+
const status_number = Number(response2.status);
|
|
529
|
+
if (isNaN(status_number)) throw new Error(`response.status is not a number. value: "${response2.status}" type: ${typeof response2.status}`);
|
|
530
|
+
const request_body = input instanceof Request && cloned_body ? await new Response(cloned_body).text() : init2?.body;
|
|
531
|
+
if (request_body && typeof request_body !== "string" && !ArrayBuffer.isView(request_body)) return;
|
|
532
|
+
fetched.push({
|
|
533
|
+
url: fetch_cache_url(url, event.url),
|
|
534
|
+
method: event.request.method,
|
|
535
|
+
request_body,
|
|
536
|
+
request_headers: cloned_headers,
|
|
537
|
+
response_body: body,
|
|
538
|
+
response: response2,
|
|
539
|
+
is_b64
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
if (key === "body") {
|
|
543
|
+
if (response2.body === null) return null;
|
|
544
|
+
if (teed_body) return teed_body;
|
|
545
|
+
const [a, b] = response2.body.tee();
|
|
546
|
+
(async () => {
|
|
547
|
+
const result = new Uint8Array(await new Response(a).arrayBuffer());
|
|
548
|
+
if (dependency) dependency.body = new Uint8Array(result);
|
|
549
|
+
push_fetched(base64_encode(result), true);
|
|
550
|
+
})().catch(noop);
|
|
551
|
+
return teed_body = b;
|
|
552
|
+
}
|
|
553
|
+
if (key === "arrayBuffer") return async () => {
|
|
554
|
+
const buffer = await response2.arrayBuffer();
|
|
555
|
+
const bytes = new Uint8Array(buffer);
|
|
556
|
+
if (dependency) dependency.body = bytes;
|
|
557
|
+
if (buffer instanceof ArrayBuffer) await push_fetched(base64_encode(bytes), true);
|
|
558
|
+
return buffer;
|
|
559
|
+
};
|
|
560
|
+
async function text2() {
|
|
561
|
+
const body = await response2.text();
|
|
562
|
+
if (body === "" && NULL_BODY_STATUS.includes(response2.status)) {
|
|
563
|
+
await push_fetched(void 0, false);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (!body || typeof body === "string") await push_fetched(body, false);
|
|
567
|
+
if (dependency) dependency.body = body;
|
|
568
|
+
return body;
|
|
569
|
+
}
|
|
570
|
+
if (key === "text") return text2;
|
|
571
|
+
if (key === "json") return async () => {
|
|
572
|
+
const body = await text2();
|
|
573
|
+
return body ? JSON.parse(body) : void 0;
|
|
574
|
+
};
|
|
575
|
+
const value = Reflect.get(response2, key, response2);
|
|
576
|
+
if (value instanceof Function) return Object.defineProperties(
|
|
577
|
+
/**
|
|
578
|
+
* @this {any}
|
|
579
|
+
*/
|
|
580
|
+
function() {
|
|
581
|
+
return Reflect.apply(value, this === receiver ? response2 : this, arguments);
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: { value: value.name },
|
|
585
|
+
length: { value: value.length }
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
return value;
|
|
589
|
+
} });
|
|
590
|
+
if (csr) {
|
|
591
|
+
const get = response.headers.get;
|
|
592
|
+
response.headers.get = (key) => {
|
|
593
|
+
const lower = key.toLowerCase();
|
|
594
|
+
const value = get.call(response.headers, lower);
|
|
595
|
+
if (value && !lower.startsWith("x-sveltekit-")) {
|
|
596
|
+
if (!resolve_opts.filterSerializedResponseHeaders(lower, value)) load_response_header_not_serialized({
|
|
597
|
+
name: lower,
|
|
598
|
+
id: event.route.id
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
return value;
|
|
602
|
+
};
|
|
603
|
+
const get_set_cookie = response.headers.getSetCookie;
|
|
604
|
+
response.headers.getSetCookie = () => {
|
|
605
|
+
const values = get_set_cookie.call(response.headers);
|
|
606
|
+
for (const value of values) if (!resolve_opts.filterSerializedResponseHeaders("set-cookie", value)) load_response_header_not_serialized({
|
|
607
|
+
name: "set-cookie",
|
|
608
|
+
id: event.route.id
|
|
609
|
+
});
|
|
610
|
+
return values;
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
return proxy;
|
|
614
|
+
};
|
|
615
|
+
return (input, init2) => {
|
|
616
|
+
const response = universal_fetch(input, init2);
|
|
617
|
+
response.catch(noop);
|
|
618
|
+
return response;
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function hash(...values) {
|
|
622
|
+
let hash2 = 5381;
|
|
623
|
+
for (const value of values) if (typeof value === "string") {
|
|
624
|
+
let i = value.length;
|
|
625
|
+
while (i) hash2 = hash2 * 33 ^ value.charCodeAt(--i);
|
|
626
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
627
|
+
const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
628
|
+
let i = buffer.length;
|
|
629
|
+
while (i) hash2 = hash2 * 33 ^ buffer[--i];
|
|
630
|
+
} else throw new TypeError("value must be a string or TypedArray");
|
|
631
|
+
return (hash2 >>> 0).toString(36);
|
|
632
|
+
}
|
|
633
|
+
function hash_request(headers2, body) {
|
|
634
|
+
const values = [];
|
|
635
|
+
if (headers2) values.push([...new Headers(headers2)].join(","));
|
|
636
|
+
if (body) values.push(body);
|
|
637
|
+
return hash(...values);
|
|
638
|
+
}
|
|
639
|
+
var s = JSON.stringify;
|
|
640
|
+
var escape_html_attr_dict = {
|
|
641
|
+
"&": "&",
|
|
642
|
+
'"': """
|
|
643
|
+
};
|
|
644
|
+
var escape_html_dict = {
|
|
645
|
+
"&": "&",
|
|
646
|
+
"<": "<"
|
|
647
|
+
};
|
|
648
|
+
var escape_regex = (dict) => new RegExp(`[${Object.keys(dict).join("")}]|\\p{Surrogate}`, "gu");
|
|
649
|
+
var escape_html_attr_regex = escape_regex(escape_html_attr_dict);
|
|
650
|
+
var escape_html_regex = escape_regex(escape_html_dict);
|
|
651
|
+
function escape_html2(str, is_attr) {
|
|
652
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
653
|
+
return str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => dict[match] ?? `&#${match.charCodeAt(0)};`);
|
|
654
|
+
}
|
|
655
|
+
var replacements = {
|
|
656
|
+
"<": "\\u003C",
|
|
657
|
+
"\u2028": "\\u2028",
|
|
658
|
+
"\u2029": "\\u2029"
|
|
659
|
+
};
|
|
660
|
+
var pattern = new RegExp(`[${Object.keys(replacements).join("")}]`, "g");
|
|
661
|
+
function serialize_data(fetched, filter, prerendering = false) {
|
|
662
|
+
const headers2 = {};
|
|
663
|
+
let cache_control = null;
|
|
664
|
+
let age = null;
|
|
665
|
+
let varyAny = false;
|
|
666
|
+
for (const [key, value] of fetched.response.headers) {
|
|
667
|
+
if (filter(key, value)) headers2[key] = value;
|
|
668
|
+
if (key === "cache-control") cache_control = value;
|
|
669
|
+
else if (key === "age") age = value;
|
|
670
|
+
else if (key === "vary" && value.trim() === "*") varyAny = true;
|
|
671
|
+
}
|
|
672
|
+
const payload2 = {
|
|
673
|
+
status: fetched.response.status,
|
|
674
|
+
statusText: fetched.response.statusText,
|
|
675
|
+
headers: headers2,
|
|
676
|
+
body: fetched.response_body
|
|
677
|
+
};
|
|
678
|
+
const safe_payload = JSON.stringify(payload2).replace(pattern, (match) => replacements[match]);
|
|
679
|
+
const attrs = [
|
|
680
|
+
'type="application/json"',
|
|
681
|
+
"data-sveltekit-fetched",
|
|
682
|
+
`data-url="${escape_html2(fetched.url, true)}"`
|
|
683
|
+
];
|
|
684
|
+
if (fetched.is_b64) attrs.push("data-b64");
|
|
685
|
+
if (fetched.request_headers || fetched.request_body) attrs.push(`data-hash="${hash_request(fetched.request_headers, fetched.request_body)}"`);
|
|
686
|
+
if (!prerendering && fetched.method === "GET" && cache_control && !varyAny) {
|
|
687
|
+
const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
|
|
688
|
+
if (match) {
|
|
689
|
+
const ttl = +match[1] - +(age ?? "0");
|
|
690
|
+
attrs.push(`data-ttl="${ttl}"`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return `<script ${attrs.join(" ")}>${safe_payload}</script>`;
|
|
694
|
+
}
|
|
695
|
+
var array = /* @__PURE__ */ new Uint8Array(16);
|
|
696
|
+
function generate_nonce() {
|
|
697
|
+
crypto.getRandomValues(array);
|
|
698
|
+
return base64_encode(array);
|
|
699
|
+
}
|
|
700
|
+
async function sha256(content) {
|
|
701
|
+
const digest = await crypto.subtle.digest("SHA-256", text_encoder.encode(content));
|
|
702
|
+
return base64_encode(new Uint8Array(digest));
|
|
703
|
+
}
|
|
704
|
+
var quoted = /* @__PURE__ */ new Set([
|
|
705
|
+
"self",
|
|
706
|
+
"unsafe-eval",
|
|
707
|
+
"unsafe-hashes",
|
|
708
|
+
"unsafe-inline",
|
|
709
|
+
"none",
|
|
710
|
+
"strict-dynamic",
|
|
711
|
+
"report-sample",
|
|
712
|
+
"report-sha256",
|
|
713
|
+
"report-sha384",
|
|
714
|
+
"report-sha512",
|
|
715
|
+
"wasm-unsafe-eval",
|
|
716
|
+
"script"
|
|
717
|
+
]);
|
|
718
|
+
var crypto_pattern = /^(nonce|sha\d\d\d)-/;
|
|
719
|
+
var BaseProvider = class {
|
|
720
|
+
/** @type {boolean} */
|
|
721
|
+
#use_hashes;
|
|
722
|
+
/** @type {boolean} */
|
|
723
|
+
script_needs_csp;
|
|
724
|
+
/** @type {boolean} */
|
|
725
|
+
#script_src_needs_csp;
|
|
726
|
+
/** @type {boolean} */
|
|
727
|
+
#script_src_elem_needs_csp;
|
|
728
|
+
/** @type {boolean} */
|
|
729
|
+
style_needs_csp;
|
|
730
|
+
/** @type {boolean} */
|
|
731
|
+
#style_src_needs_csp;
|
|
732
|
+
/** @type {boolean} */
|
|
733
|
+
#style_src_attr_needs_csp;
|
|
734
|
+
/** @type {boolean} */
|
|
735
|
+
#style_src_elem_needs_csp;
|
|
736
|
+
/** @type {import('types').CspDirectives} */
|
|
737
|
+
#directives;
|
|
738
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
739
|
+
#script_src = /* @__PURE__ */ new Set();
|
|
740
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
741
|
+
#script_src_elem = /* @__PURE__ */ new Set();
|
|
742
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
743
|
+
#style_src = /* @__PURE__ */ new Set();
|
|
744
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
745
|
+
#style_src_attr = /* @__PURE__ */ new Set();
|
|
746
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
747
|
+
#style_src_elem = /* @__PURE__ */ new Set();
|
|
748
|
+
/** @type {boolean} */
|
|
749
|
+
script_needs_nonce;
|
|
750
|
+
/** @type {boolean} */
|
|
751
|
+
style_needs_nonce;
|
|
752
|
+
/** @type {boolean} */
|
|
753
|
+
script_needs_hash;
|
|
754
|
+
/**
|
|
755
|
+
* @param {boolean} use_hashes
|
|
756
|
+
* @param {import('types').CspDirectives} directives
|
|
757
|
+
*/
|
|
758
|
+
constructor(use_hashes, directives) {
|
|
759
|
+
this.#use_hashes = use_hashes;
|
|
760
|
+
this.#directives = directives;
|
|
761
|
+
const d = this.#directives;
|
|
762
|
+
const effective_script_src = d["script-src"] || d["default-src"];
|
|
763
|
+
const script_src_elem = d["script-src-elem"];
|
|
764
|
+
const effective_style_src = d["style-src"] || d["default-src"];
|
|
765
|
+
const style_src_attr = d["style-src-attr"];
|
|
766
|
+
const style_src_elem = d["style-src-elem"];
|
|
767
|
+
const style_needs_csp = (directive) => !!directive && !directive.some((value) => value === "unsafe-inline");
|
|
768
|
+
const script_needs_csp = (directive) => !!directive && (!directive.some((value) => value === "unsafe-inline") || directive.some((value) => value === "strict-dynamic"));
|
|
769
|
+
this.#script_src_needs_csp = script_needs_csp(effective_script_src);
|
|
770
|
+
this.#script_src_elem_needs_csp = script_needs_csp(script_src_elem);
|
|
771
|
+
this.#style_src_needs_csp = style_needs_csp(effective_style_src);
|
|
772
|
+
this.#style_src_attr_needs_csp = style_needs_csp(style_src_attr);
|
|
773
|
+
this.#style_src_elem_needs_csp = style_needs_csp(style_src_elem);
|
|
774
|
+
this.script_needs_csp = this.#script_src_needs_csp || this.#script_src_elem_needs_csp;
|
|
775
|
+
this.style_needs_csp = this.#style_src_needs_csp || this.#style_src_attr_needs_csp || this.#style_src_elem_needs_csp;
|
|
776
|
+
this.script_needs_nonce = this.script_needs_csp && !this.#use_hashes;
|
|
777
|
+
this.style_needs_nonce = this.style_needs_csp && !this.#use_hashes;
|
|
778
|
+
this.script_needs_hash = this.script_needs_csp && this.#use_hashes;
|
|
779
|
+
}
|
|
780
|
+
/** @param {CspSource} source */
|
|
781
|
+
add_script(source) {
|
|
782
|
+
if (this.#script_src_needs_csp) this.#script_src.add(source);
|
|
783
|
+
if (this.#script_src_elem_needs_csp) this.#script_src_elem.add(source);
|
|
784
|
+
}
|
|
785
|
+
/** @param {CspSource} source */
|
|
786
|
+
add_style(source) {
|
|
787
|
+
if (!this.style_needs_csp) return;
|
|
788
|
+
if (this.#style_src_needs_csp) this.#style_src.add(source);
|
|
789
|
+
if (this.#style_src_attr_needs_csp) this.#style_src_attr.add(source);
|
|
790
|
+
if (this.#style_src_elem_needs_csp) {
|
|
791
|
+
const sha256_empty_comment_hash = "sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=";
|
|
792
|
+
const d = this.#directives;
|
|
793
|
+
if (d["style-src-elem"] && !d["style-src-elem"].includes(sha256_empty_comment_hash) && !this.#style_src_elem.has(sha256_empty_comment_hash)) this.#style_src_elem.add(sha256_empty_comment_hash);
|
|
794
|
+
if (source !== sha256_empty_comment_hash) this.#style_src_elem.add(source);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* @param {boolean} [is_meta]
|
|
799
|
+
*/
|
|
800
|
+
get_header(is_meta = false) {
|
|
801
|
+
const header = [];
|
|
802
|
+
const directives = { ...this.#directives };
|
|
803
|
+
const merge_sources = (key, sources, base) => {
|
|
804
|
+
if (sources.size > 0) directives[key] = [...base || [], ...sources];
|
|
805
|
+
};
|
|
806
|
+
merge_sources("style-src", this.#style_src, directives["style-src"] || directives["default-src"]);
|
|
807
|
+
merge_sources("style-src-attr", this.#style_src_attr, directives["style-src-attr"]);
|
|
808
|
+
merge_sources("style-src-elem", this.#style_src_elem, directives["style-src-elem"]);
|
|
809
|
+
merge_sources("script-src", this.#script_src, directives["script-src"] || directives["default-src"]);
|
|
810
|
+
merge_sources("script-src-elem", this.#script_src_elem, directives["script-src-elem"]);
|
|
811
|
+
for (const key in directives) {
|
|
812
|
+
if (is_meta && (key === "frame-ancestors" || key === "report-uri" || key === "sandbox")) continue;
|
|
813
|
+
const value = directives[key];
|
|
814
|
+
if (!value) continue;
|
|
815
|
+
const directive = [key];
|
|
816
|
+
if (Array.isArray(value)) for (const source of value) directive.push(quoted.has(source) || crypto_pattern.test(source) ? `'${source}'` : source);
|
|
817
|
+
header.push(directive.join(" "));
|
|
818
|
+
}
|
|
819
|
+
return header.join("; ");
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
var CspProvider = class extends BaseProvider {
|
|
823
|
+
get_meta() {
|
|
824
|
+
const content = this.get_header(true);
|
|
825
|
+
if (!content) return;
|
|
826
|
+
return `<meta http-equiv="content-security-policy" content="${escape_html2(content, true)}">`;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
var CspReportOnlyProvider = class extends BaseProvider {
|
|
830
|
+
/**
|
|
831
|
+
* @param {boolean} use_hashes
|
|
832
|
+
* @param {import('types').CspDirectives} directives
|
|
833
|
+
*/
|
|
834
|
+
constructor(use_hashes, directives) {
|
|
835
|
+
super(use_hashes, directives);
|
|
836
|
+
if (Object.values(directives).some((v) => !!v) && !directives["report-to"]?.length && !directives["report-uri"]?.length) csp_report_only_missing_report();
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var Csp = class {
|
|
840
|
+
/** @readonly */
|
|
841
|
+
nonce = generate_nonce();
|
|
842
|
+
/** @type {CspProvider} */
|
|
843
|
+
csp_provider;
|
|
844
|
+
/** @type {CspReportOnlyProvider} */
|
|
845
|
+
report_only_provider;
|
|
846
|
+
/** @type {boolean} */
|
|
847
|
+
#use_hashes;
|
|
848
|
+
/**
|
|
849
|
+
* @param {import('./types.js').CspConfig} config
|
|
850
|
+
* @param {import('./types.js').CspOpts} opts
|
|
851
|
+
*/
|
|
852
|
+
constructor({ mode, directives, reportOnly }, { prerender }) {
|
|
853
|
+
this.#use_hashes = mode === "hash" || mode === "auto" && prerender;
|
|
854
|
+
this.csp_provider = new CspProvider(this.#use_hashes, directives);
|
|
855
|
+
this.report_only_provider = new CspReportOnlyProvider(this.#use_hashes, reportOnly);
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* @param {string} content
|
|
859
|
+
* @returns {Promise<CspSource>}
|
|
860
|
+
*/
|
|
861
|
+
async #get_source(content) {
|
|
862
|
+
return this.#use_hashes ? `sha256-${await sha256(content)}` : `nonce-${this.nonce}`;
|
|
863
|
+
}
|
|
864
|
+
get script_needs_hash() {
|
|
865
|
+
return this.csp_provider.script_needs_hash || this.report_only_provider.script_needs_hash;
|
|
866
|
+
}
|
|
867
|
+
get script_needs_nonce() {
|
|
868
|
+
return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
|
|
869
|
+
}
|
|
870
|
+
get style_needs_nonce() {
|
|
871
|
+
return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
|
|
872
|
+
}
|
|
873
|
+
/** @param {string} content */
|
|
874
|
+
async add_script(content) {
|
|
875
|
+
if (!this.csp_provider.script_needs_csp && !this.report_only_provider.script_needs_csp) return;
|
|
876
|
+
const source = await this.#get_source(content);
|
|
877
|
+
if (this.csp_provider.script_needs_csp) this.csp_provider.add_script(source);
|
|
878
|
+
if (this.report_only_provider.script_needs_csp) this.report_only_provider.add_script(source);
|
|
879
|
+
}
|
|
880
|
+
/** @param {`sha256-${string}`[]} hashes */
|
|
881
|
+
add_script_hashes(hashes) {
|
|
882
|
+
for (const hash2 of hashes) {
|
|
883
|
+
this.csp_provider.add_script(hash2);
|
|
884
|
+
this.report_only_provider.add_script(hash2);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
/** @param {string} content */
|
|
888
|
+
async add_style(content) {
|
|
889
|
+
if (!this.csp_provider.style_needs_csp && !this.report_only_provider.style_needs_csp) return;
|
|
890
|
+
const source = await this.#get_source(content);
|
|
891
|
+
this.csp_provider.add_style(source);
|
|
892
|
+
this.report_only_provider.add_style(source);
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
function generate_route_object(route, url, client) {
|
|
896
|
+
const { errors, layouts, leaf } = route;
|
|
897
|
+
const paths = resolve_paths(url.pathname);
|
|
898
|
+
const nodes = [
|
|
899
|
+
...errors,
|
|
900
|
+
...layouts.map((l) => l?.[1]),
|
|
901
|
+
leaf[1]
|
|
902
|
+
].filter((n) => typeof n === "number").map((n) => `'${n}': () => ${create_client_import(client.nodes?.[n], paths)}`).join(",\n ");
|
|
903
|
+
return [
|
|
904
|
+
`{
|
|
905
|
+
id: ${s(route.id)}`,
|
|
906
|
+
`errors: ${s(route.errors)}`,
|
|
907
|
+
`layouts: ${s(route.layouts)}`,
|
|
908
|
+
`leaf: ${s(route.leaf)}`,
|
|
909
|
+
`nodes: {
|
|
910
|
+
${nodes}
|
|
911
|
+
}
|
|
912
|
+
}`
|
|
913
|
+
].join(",\n ");
|
|
914
|
+
}
|
|
915
|
+
function resolve_paths(pathname) {
|
|
916
|
+
const relative_base = pathname.slice(0).split("/").slice(2).map(() => "..").join("/") || ".";
|
|
917
|
+
return {
|
|
918
|
+
base: relative_base,
|
|
919
|
+
assets: !assets || assets[0] === "/" && assets !== "/_svelte_kit_assets" ? relative_base : assets
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
function client_path(path, { base, assets: assets2 }) {
|
|
923
|
+
return path[0] === "/" ? base + path : `${assets2}/${path}`;
|
|
924
|
+
}
|
|
925
|
+
function create_client_import(import_path, paths) {
|
|
926
|
+
return import_path ? `import('${client_path(import_path, paths)}')` : "Promise.resolve({})";
|
|
927
|
+
}
|
|
928
|
+
async function resolve_route(resolved_path, url) {
|
|
929
|
+
if (!manifest.client?.routes) return text("Server-side route resolution disabled", { status: 400 });
|
|
930
|
+
try {
|
|
931
|
+
const matchers = await manifest.matchers();
|
|
932
|
+
const result = find_route(resolved_path, manifest.client.routes, matchers);
|
|
933
|
+
return create_server_routing_response(result?.route ?? null, result?.params ?? {}, url, manifest.client).response;
|
|
934
|
+
} catch {
|
|
935
|
+
return text("Error resolving route", { status: 500 });
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function resolve_route_by_id(route_id, url) {
|
|
939
|
+
if (!manifest.client?.routes) return text("Server-side route resolution disabled", { status: 400 });
|
|
940
|
+
try {
|
|
941
|
+
const route = manifest.client.routes.find((r) => r.id === route_id);
|
|
942
|
+
if (route) return create_server_routing_response(route, null, url, manifest.client).response;
|
|
943
|
+
if (manifest.routes.some((r) => r.id === route_id && !r.page)) return text("export const endpoint_only = true;", { headers: js_headers() });
|
|
944
|
+
return create_server_routing_response(null, null, url, manifest.client).response;
|
|
945
|
+
} catch {
|
|
946
|
+
return text("Error resolving route", { status: 500 });
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
function js_headers() {
|
|
950
|
+
return new Headers({ "content-type": "application/javascript; charset=utf-8" });
|
|
951
|
+
}
|
|
952
|
+
function create_server_routing_response(route, params, url, client) {
|
|
953
|
+
const headers2 = js_headers();
|
|
954
|
+
let body = "";
|
|
955
|
+
if (route) {
|
|
956
|
+
const csr_route = generate_route_object(route, url, client);
|
|
957
|
+
body = `${create_css_import(route, url, client)}export const route = ${csr_route};`;
|
|
958
|
+
if (params !== null) body += `
|
|
959
|
+
export const params = ${uneval(params)}`;
|
|
960
|
+
}
|
|
961
|
+
return {
|
|
962
|
+
response: text(body, { headers: headers2 }),
|
|
963
|
+
body
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
function create_css_import(route, url, client) {
|
|
967
|
+
const { errors, layouts, leaf } = route;
|
|
968
|
+
const paths = resolve_paths(url.pathname);
|
|
969
|
+
let css = "";
|
|
970
|
+
for (const node of [
|
|
971
|
+
...errors,
|
|
972
|
+
...layouts.map((l) => l?.[1]),
|
|
973
|
+
leaf[1]
|
|
974
|
+
]) {
|
|
975
|
+
if (typeof node !== "number") continue;
|
|
976
|
+
const node_css = client.css?.[node];
|
|
977
|
+
for (const css_path of node_css ?? []) css += `'${client_path(css_path, paths)}',`;
|
|
978
|
+
}
|
|
979
|
+
if (!css) return "";
|
|
980
|
+
return `${create_client_import(client.start, paths)}.then(x => x.load_css([${css}]));
|
|
981
|
+
`;
|
|
982
|
+
}
|
|
983
|
+
var afterNavigate = noop;
|
|
984
|
+
disallow_on_server("disableScrollHandling", "()");
|
|
985
|
+
disallow_on_server("goto");
|
|
986
|
+
disallow_on_server("invalidate");
|
|
987
|
+
disallow_on_server("invalidateAll", "()");
|
|
988
|
+
disallow_on_server("refreshAll", "()");
|
|
989
|
+
disallow_on_server("preloadCode");
|
|
990
|
+
disallow_on_server("preloadData");
|
|
991
|
+
disallow_on_server("pushState");
|
|
992
|
+
disallow_on_server("replaceState");
|
|
993
|
+
function Root($$renderer, $$props) {
|
|
994
|
+
$$renderer.component(($$renderer2) => {
|
|
995
|
+
const { page, components, onerror, tree, form, error } = $$props;
|
|
996
|
+
let mounted = false;
|
|
997
|
+
let navigated = false;
|
|
998
|
+
let title = "";
|
|
999
|
+
afterNavigate(() => {
|
|
1000
|
+
if (mounted) {
|
|
1001
|
+
navigated = true;
|
|
1002
|
+
title = document.title || "untitled page";
|
|
1003
|
+
} else mounted = true;
|
|
1004
|
+
});
|
|
1005
|
+
function node($$renderer3, n, depth) {
|
|
1006
|
+
const Component = derived(() => n.component);
|
|
1007
|
+
const Error2 = derived(() => n.error);
|
|
1008
|
+
const data = derived(() => n.data);
|
|
1009
|
+
function failed($$renderer4, error2) {
|
|
1010
|
+
if (Error2()) {
|
|
1011
|
+
$$renderer4.push("<!--[-->");
|
|
1012
|
+
Error2()($$renderer4, { error: error2 });
|
|
1013
|
+
$$renderer4.push("<!--]-->");
|
|
1014
|
+
} else {
|
|
1015
|
+
$$renderer4.push("<!--[!-->");
|
|
1016
|
+
$$renderer4.push("<!--]-->");
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
$$renderer3.boundary({ failed: Error2() ? failed : void 0 }, ($$renderer4) => {
|
|
1020
|
+
$$renderer4.push(`<!--[-->`);
|
|
1021
|
+
if (n.child) {
|
|
1022
|
+
$$renderer4.push("<!--[0-->");
|
|
1023
|
+
if (Component()) {
|
|
1024
|
+
$$renderer4.push("<!--[-->");
|
|
1025
|
+
Component()($$renderer4, {
|
|
1026
|
+
data: data(),
|
|
1027
|
+
form,
|
|
1028
|
+
params: page.params,
|
|
1029
|
+
children: ($$renderer5) => {
|
|
1030
|
+
node($$renderer5, n.child, depth + 1);
|
|
1031
|
+
},
|
|
1032
|
+
$$slots: { default: true }
|
|
1033
|
+
});
|
|
1034
|
+
$$renderer4.push("<!--]-->");
|
|
1035
|
+
} else {
|
|
1036
|
+
$$renderer4.push("<!--[!-->");
|
|
1037
|
+
$$renderer4.push("<!--]-->");
|
|
1038
|
+
}
|
|
1039
|
+
} else {
|
|
1040
|
+
$$renderer4.push("<!--[-1-->");
|
|
1041
|
+
if (Component()) {
|
|
1042
|
+
$$renderer4.push("<!--[-->");
|
|
1043
|
+
Component()($$renderer4, {
|
|
1044
|
+
data: data(),
|
|
1045
|
+
form,
|
|
1046
|
+
params: page.params,
|
|
1047
|
+
error
|
|
1048
|
+
});
|
|
1049
|
+
$$renderer4.push("<!--]-->");
|
|
1050
|
+
} else {
|
|
1051
|
+
$$renderer4.push("<!--[!-->");
|
|
1052
|
+
$$renderer4.push("<!--]-->");
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
$$renderer4.push(`<!--]-->`);
|
|
1056
|
+
$$renderer4.push(`<!--]-->`);
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
node($$renderer2, tree, 0);
|
|
1060
|
+
$$renderer2.push(`<!----> `);
|
|
1061
|
+
if (mounted) {
|
|
1062
|
+
$$renderer2.push(`<!--[0--><div id="svelte-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px">`);
|
|
1063
|
+
if (navigated) $$renderer2.push(`<!--[0-->${escape_html(title)}`);
|
|
1064
|
+
else $$renderer2.push("<!--[-1-->");
|
|
1065
|
+
$$renderer2.push(`<!--]--></div>`);
|
|
1066
|
+
} else $$renderer2.push("<!--[-1-->");
|
|
1067
|
+
$$renderer2.push(`<!--]-->`);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
var Props = class {
|
|
1071
|
+
/** @type {Page} */
|
|
1072
|
+
page;
|
|
1073
|
+
/**
|
|
1074
|
+
* An array of the `+layout.svelte` and `+page.svelte` component instances
|
|
1075
|
+
* that currently live on the page — used for capturing and restoring snapshots.
|
|
1076
|
+
* It's updated/manipulated through `bind:this` in `Root.svelte`.
|
|
1077
|
+
* @type {Array<Record<string, any>>}
|
|
1078
|
+
* @deprecated only used for `export const snapshot` — TODO 4.0 get rid
|
|
1079
|
+
*/
|
|
1080
|
+
components = [];
|
|
1081
|
+
/** @type {any} */
|
|
1082
|
+
form;
|
|
1083
|
+
/** @type {App.Error | undefined} */
|
|
1084
|
+
error;
|
|
1085
|
+
/** @type {RenderNode} */
|
|
1086
|
+
tree;
|
|
1087
|
+
/** @type {(error: unknown, reset: () => void) => void} */
|
|
1088
|
+
onerror;
|
|
1089
|
+
/**
|
|
1090
|
+
* @param {{
|
|
1091
|
+
* page: Page;
|
|
1092
|
+
* tree: RenderNode;
|
|
1093
|
+
* form: any;
|
|
1094
|
+
* error: App.Error | undefined;
|
|
1095
|
+
* onerror?: (error: unknown, reset: () => void) => void;
|
|
1096
|
+
* }} props
|
|
1097
|
+
*/
|
|
1098
|
+
constructor({ page, tree, form, error, onerror = noop }) {
|
|
1099
|
+
this.page = page;
|
|
1100
|
+
this.tree = tree;
|
|
1101
|
+
this.onerror = onerror;
|
|
1102
|
+
this.form = form;
|
|
1103
|
+
this.error = error;
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
var RenderNode = class {
|
|
1107
|
+
/** @type {Component} */
|
|
1108
|
+
component;
|
|
1109
|
+
/** @type {Component | undefined} */
|
|
1110
|
+
error;
|
|
1111
|
+
/** @type {Record<string, any>} */
|
|
1112
|
+
data = {};
|
|
1113
|
+
/** @type {RenderNode | undefined} */
|
|
1114
|
+
child;
|
|
1115
|
+
/**
|
|
1116
|
+
*
|
|
1117
|
+
* @param {Component} component
|
|
1118
|
+
* @param {Component | undefined} error
|
|
1119
|
+
*/
|
|
1120
|
+
constructor(component, error) {
|
|
1121
|
+
this.component = component;
|
|
1122
|
+
this.error = error;
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
async function render_response({ branch, fetched, page_config, status, error = null, event, state, resolve_opts, action_result, data_serializer, error_components }) {
|
|
1126
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
1127
|
+
if (options.csp.mode === "nonce") prerender_nonce();
|
|
1128
|
+
if (options.app_template_contains_nonce) prerender_template_nonce({ tag: "%sveltekit.nonce%" });
|
|
1129
|
+
}
|
|
1130
|
+
const client = manifest.client;
|
|
1131
|
+
const modulepreloads = new Set(client?.imports);
|
|
1132
|
+
const stylesheets = new Set(client?.stylesheets);
|
|
1133
|
+
const fonts = new Map(client?.fonts.map((font) => [font.file, font]));
|
|
1134
|
+
const inline_styles = /* @__PURE__ */ new Map();
|
|
1135
|
+
let rendered;
|
|
1136
|
+
const form_value = action_result?.type === "success" || action_result?.type === "failure" ? action_result.data ?? null : null;
|
|
1137
|
+
let base = "";
|
|
1138
|
+
let assets$1 = assets;
|
|
1139
|
+
let base_expression = s("");
|
|
1140
|
+
const csp = new Csp(options.csp, { prerender: !!(state.prerendering || state.prerender_default === true) });
|
|
1141
|
+
if (!state.prerendering?.fallback) {
|
|
1142
|
+
const pathname = event.isDataRequest ? add_data_suffix(event.url.pathname) : event.url.pathname;
|
|
1143
|
+
({ base, assets: assets$1 } = resolve_paths(pathname));
|
|
1144
|
+
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
|
|
1145
|
+
}
|
|
1146
|
+
if (page_config.ssr) {
|
|
1147
|
+
const props = new Props({
|
|
1148
|
+
page: {
|
|
1149
|
+
error,
|
|
1150
|
+
params: event.params,
|
|
1151
|
+
route: event.route,
|
|
1152
|
+
status,
|
|
1153
|
+
url: event.url,
|
|
1154
|
+
data: {},
|
|
1155
|
+
form: form_value,
|
|
1156
|
+
shallow: null,
|
|
1157
|
+
state: {}
|
|
1158
|
+
},
|
|
1159
|
+
tree: new RenderNode(await branch[0].node.component?.(), void 0),
|
|
1160
|
+
form: form_value,
|
|
1161
|
+
error: error ?? void 0
|
|
1162
|
+
});
|
|
1163
|
+
let current_node = props.tree;
|
|
1164
|
+
let data2 = props.page.data;
|
|
1165
|
+
for (let i = 0; i < branch.length; i += 1) {
|
|
1166
|
+
const node = branch[i];
|
|
1167
|
+
data2 = {
|
|
1168
|
+
...data2,
|
|
1169
|
+
...node.data
|
|
1170
|
+
};
|
|
1171
|
+
current_node.data = data2;
|
|
1172
|
+
if (i < branch.length - 1) current_node = current_node.child = new RenderNode(await branch[i + 1].node.component?.(), error_components?.[i + 1]);
|
|
1173
|
+
}
|
|
1174
|
+
props.page.data = data2;
|
|
1175
|
+
const render_state = {
|
|
1176
|
+
...state,
|
|
1177
|
+
is_in_render: true
|
|
1178
|
+
};
|
|
1179
|
+
const render_opts = {
|
|
1180
|
+
context: /* @__PURE__ */ new Map([["__request__", { page: props.page }]]),
|
|
1181
|
+
csp: csp.script_needs_nonce ? { nonce: csp.nonce } : { hash: csp.script_needs_hash },
|
|
1182
|
+
transformError: error_components ? (e) => {
|
|
1183
|
+
if (isRedirect(e)) throw e;
|
|
1184
|
+
const handled = handle_error_and_jsonify(event, render_state, e);
|
|
1185
|
+
if (handled instanceof Promise) return handled.then((e2) => {
|
|
1186
|
+
error = e2;
|
|
1187
|
+
props.page.error = error;
|
|
1188
|
+
props.page.status = status = error.status;
|
|
1189
|
+
return error;
|
|
1190
|
+
});
|
|
1191
|
+
error = handled;
|
|
1192
|
+
props.page.error = error;
|
|
1193
|
+
props.page.status = status = error.status;
|
|
1194
|
+
return error;
|
|
1195
|
+
} : void 0
|
|
1196
|
+
};
|
|
1197
|
+
globalThis.fetch;
|
|
1198
|
+
try {
|
|
1199
|
+
rendered = await with_request_store({
|
|
1200
|
+
event,
|
|
1201
|
+
state: render_state
|
|
1202
|
+
}, async () => {
|
|
1203
|
+
return render(Root, {
|
|
1204
|
+
...render_opts,
|
|
1205
|
+
props
|
|
1206
|
+
});
|
|
1207
|
+
});
|
|
1208
|
+
if (rendered.hashes) csp.add_script_hashes(rendered.hashes.script);
|
|
1209
|
+
} finally {
|
|
1210
|
+
}
|
|
1211
|
+
} else rendered = {
|
|
1212
|
+
head: "",
|
|
1213
|
+
body: "",
|
|
1214
|
+
hashes: { script: [] }
|
|
1215
|
+
};
|
|
1216
|
+
for (const { node } of branch) {
|
|
1217
|
+
for (const url of node.imports) modulepreloads.add(url);
|
|
1218
|
+
for (const url of node.stylesheets) stylesheets.add(url);
|
|
1219
|
+
for (const font of node.fonts) fonts.set(font.file, font);
|
|
1220
|
+
if (node.inline_styles && !client?.inline) Object.entries(await node.inline_styles()).forEach(([filename, css]) => {
|
|
1221
|
+
if (typeof css === "string") {
|
|
1222
|
+
inline_styles.set(filename, css);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
inline_styles.set(filename, css(`${assets$1}/${app_dir}/immutable/assets`, assets$1));
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
const head = new Head(rendered.head);
|
|
1229
|
+
let body = rendered.body;
|
|
1230
|
+
const prefixed = (path) => client_path(path, {
|
|
1231
|
+
base,
|
|
1232
|
+
assets: assets$1
|
|
1233
|
+
});
|
|
1234
|
+
const style = client?.inline ? client.inline?.style : Array.from(inline_styles.values()).join("\n");
|
|
1235
|
+
if (style) {
|
|
1236
|
+
const attributes = [];
|
|
1237
|
+
if (csp.style_needs_nonce) attributes.push(`nonce="${csp.nonce}"`);
|
|
1238
|
+
await csp.add_style(style);
|
|
1239
|
+
head.add_style(style, attributes);
|
|
1240
|
+
}
|
|
1241
|
+
const add_preload = (path, attributes) => {
|
|
1242
|
+
head.add_link_tag(path, attributes);
|
|
1243
|
+
};
|
|
1244
|
+
for (const dep of stylesheets) {
|
|
1245
|
+
const path = prefixed(dep);
|
|
1246
|
+
const attributes = ['rel="stylesheet"'];
|
|
1247
|
+
if (inline_styles.has(dep)) attributes.push("disabled", 'media="(max-width: 0)"');
|
|
1248
|
+
head.add_stylesheet(path, attributes);
|
|
1249
|
+
}
|
|
1250
|
+
for (const { file, filename } of fonts.values()) {
|
|
1251
|
+
const path = prefixed(file);
|
|
1252
|
+
if (resolve_opts.preload({
|
|
1253
|
+
type: "font",
|
|
1254
|
+
path,
|
|
1255
|
+
filename
|
|
1256
|
+
})) add_preload(path, [
|
|
1257
|
+
'rel="preload"',
|
|
1258
|
+
'as="font"',
|
|
1259
|
+
`type="font/${file.slice(file.lastIndexOf(".") + 1)}"`,
|
|
1260
|
+
"crossorigin"
|
|
1261
|
+
]);
|
|
1262
|
+
}
|
|
1263
|
+
const global = "__sveltekit_1rxnxzs";
|
|
1264
|
+
const { data, chunks } = data_serializer.get_data(csp);
|
|
1265
|
+
if (page_config.ssr && page_config.csr) body += `
|
|
1266
|
+
${fetched.map((item) => serialize_data(item, resolve_opts.filterSerializedResponseHeaders, !!(state.prerendering || state.prerender_default === true))).join("\n ")}`;
|
|
1267
|
+
if (page_config.csr && client) {
|
|
1268
|
+
const route = client.routes?.find((r) => r.id === event.route.id) ?? null;
|
|
1269
|
+
const load_env_eagerly = client.uses_env_dynamic_public && (state.prerendering || state.prerender_default === true);
|
|
1270
|
+
if (load_env_eagerly) modulepreloads.add(`${app_dir}/env.js`);
|
|
1271
|
+
if (!client.inline) for (const dep of modulepreloads) {
|
|
1272
|
+
const path = prefixed(dep);
|
|
1273
|
+
if (resolve_opts.preload({
|
|
1274
|
+
type: "js",
|
|
1275
|
+
path
|
|
1276
|
+
})) add_preload(path, ['rel="modulepreload"']);
|
|
1277
|
+
}
|
|
1278
|
+
if (client.routes && state.prerendering && !state.prerendering.fallback) {
|
|
1279
|
+
const pathname = add_resolution_suffix(event.url.pathname);
|
|
1280
|
+
state.prerendering.dependencies.set(pathname, create_server_routing_response(route, event.params, new URL(pathname, event.url), client));
|
|
1281
|
+
if (route && !state.prerendering.resolved_route_ids.has(route.id)) {
|
|
1282
|
+
state.prerendering.resolved_route_ids.add(route.id);
|
|
1283
|
+
const id_pathname = "" + route_id_resolution_pathname(route.id);
|
|
1284
|
+
state.prerendering.dependencies.set(id_pathname, create_server_routing_response(route, null, new URL(id_pathname, event.url), client));
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
const blocks = [];
|
|
1288
|
+
const properties = [`base: ${base_expression}`, `version: ${s("1794327600754")}`];
|
|
1289
|
+
if (assets) properties.push(`assets: ${s(assets)}`);
|
|
1290
|
+
if (client.uses_env_dynamic_public) properties.push(`env: ${load_env_eagerly ? "null" : uneval(rendered_env)}`);
|
|
1291
|
+
if (chunks) {
|
|
1292
|
+
blocks.push("const deferred = new Map();");
|
|
1293
|
+
properties.push(`defer: (id) => new Promise((fulfil, reject) => {
|
|
1294
|
+
deferred.set(id, { fulfil, reject });
|
|
1295
|
+
})`);
|
|
1296
|
+
let app_declaration = "";
|
|
1297
|
+
if (has_custom_transporters) {
|
|
1298
|
+
if (client.inline) app_declaration = `const app = ${global}.app.app;`;
|
|
1299
|
+
else if (client.app) app_declaration = `const kit = await import(${s(prefixed(client.start))});
|
|
1300
|
+
kit.init(${global});
|
|
1301
|
+
const app = await import(${s(prefixed(client.app))});`;
|
|
1302
|
+
else app_declaration = `const { app } = await import(${s(prefixed(client.start))});`;
|
|
1303
|
+
}
|
|
1304
|
+
const prelude = app_declaration ? `${app_declaration}
|
|
1305
|
+
const [data, error] = fn(app);` : `const [data, error] = fn();`;
|
|
1306
|
+
properties.push(`resolve: async (id, fn) => {
|
|
1307
|
+
${prelude}
|
|
1308
|
+
|
|
1309
|
+
const try_to_resolve = () => {
|
|
1310
|
+
if (!deferred.has(id)) {
|
|
1311
|
+
setTimeout(try_to_resolve, 0);
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
const { fulfil, reject } = deferred.get(id);
|
|
1315
|
+
deferred.delete(id);
|
|
1316
|
+
if (error) reject(error);
|
|
1317
|
+
else fulfil(data);
|
|
1318
|
+
}
|
|
1319
|
+
try_to_resolve();
|
|
1320
|
+
}`);
|
|
1321
|
+
}
|
|
1322
|
+
blocks.push(`${global} = {
|
|
1323
|
+
${properties.join(",\n ")}
|
|
1324
|
+
};`);
|
|
1325
|
+
const args = ["element"];
|
|
1326
|
+
blocks.push("const element = document.currentScript.parentElement;");
|
|
1327
|
+
if (page_config.ssr) {
|
|
1328
|
+
const serialized = {
|
|
1329
|
+
form: "null",
|
|
1330
|
+
error: "null"
|
|
1331
|
+
};
|
|
1332
|
+
if (form_value) serialized.form = uneval_action_response(form_value, event.route.id);
|
|
1333
|
+
if (error) serialized.error = uneval(error);
|
|
1334
|
+
const hydrate = [
|
|
1335
|
+
`node_ids: [${branch.map(({ node }) => node.index).join(", ")}]`,
|
|
1336
|
+
`data: ${data}`,
|
|
1337
|
+
`form: ${serialized.form}`,
|
|
1338
|
+
`error: ${serialized.error}`
|
|
1339
|
+
];
|
|
1340
|
+
if (status !== 200 && !error) hydrate.push(`status: ${status}`);
|
|
1341
|
+
if (client.routes) {
|
|
1342
|
+
if (route) {
|
|
1343
|
+
const stringified = generate_route_object(route, event.url, client).replaceAll("\n", "\n ");
|
|
1344
|
+
hydrate.push(`params: ${uneval(event.params)}`, `server_route: ${stringified}`);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
const indent = " ".repeat(load_env_eagerly ? 7 : 6);
|
|
1348
|
+
args.push(`{
|
|
1349
|
+
${indent} ${hydrate.join(`,
|
|
1350
|
+
${indent} `)}
|
|
1351
|
+
${indent}}`);
|
|
1352
|
+
}
|
|
1353
|
+
const remote_data = await collect_remote_data({}, event, state);
|
|
1354
|
+
const serialized_data = Object.keys(remote_data).length > 0 ? `${global}.data = ${uneval2(remote_data)};
|
|
1355
|
+
|
|
1356
|
+
` : "";
|
|
1357
|
+
const boot = client.inline ? `${client.inline.script}
|
|
1358
|
+
|
|
1359
|
+
${serialized_data}${global}.app.start(${args.join(", ")});` : client.app ? `import(${s(prefixed(client.start))}).then(async (kit) => {
|
|
1360
|
+
kit.init(${global});
|
|
1361
|
+
const app = await import(${s(prefixed(client.app))});
|
|
1362
|
+
${serialized_data}kit.start(app, ${args.join(", ")});
|
|
1363
|
+
});` : `import(${s(prefixed(client.start))}).then((app) => {
|
|
1364
|
+
${serialized_data}app.start(${args.join(", ")})
|
|
1365
|
+
});`;
|
|
1366
|
+
if (load_env_eagerly) blocks.push(`import(${s(`${base}/${app_dir}/env.js`)}).then(({ env }) => {
|
|
1367
|
+
${global}.env = env;
|
|
1368
|
+
|
|
1369
|
+
${boot.replace(/\n/g, "\n ")}
|
|
1370
|
+
});`);
|
|
1371
|
+
else blocks.push(boot);
|
|
1372
|
+
const init_app = `
|
|
1373
|
+
{
|
|
1374
|
+
${blocks.join("\n\n ")}
|
|
1375
|
+
}
|
|
1376
|
+
`;
|
|
1377
|
+
await csp.add_script(init_app);
|
|
1378
|
+
body += `
|
|
1379
|
+
<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_app}</script>
|
|
1380
|
+
`;
|
|
1381
|
+
}
|
|
1382
|
+
const headers2 = new Headers({
|
|
1383
|
+
"x-sveltekit-page": "true",
|
|
1384
|
+
"content-type": "text/html"
|
|
1385
|
+
});
|
|
1386
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
1387
|
+
const csp_headers = csp.csp_provider.get_meta();
|
|
1388
|
+
if (csp_headers) head.add_http_equiv(csp_headers);
|
|
1389
|
+
if (state.prerendering?.cache) head.add_http_equiv(`<meta http-equiv="cache-control" content="${escape_html2(state.prerendering.cache, true)}">`);
|
|
1390
|
+
} else {
|
|
1391
|
+
const csp_header = csp.csp_provider.get_header();
|
|
1392
|
+
if (csp_header) headers2.set("content-security-policy", csp_header);
|
|
1393
|
+
const report_only_header = csp.report_only_provider.get_header();
|
|
1394
|
+
if (report_only_header) headers2.set("content-security-policy-report-only", report_only_header);
|
|
1395
|
+
}
|
|
1396
|
+
const html = options.templates.app({
|
|
1397
|
+
head: head.build(),
|
|
1398
|
+
body,
|
|
1399
|
+
assets: assets$1,
|
|
1400
|
+
nonce: csp.nonce,
|
|
1401
|
+
env: explicit_public_env
|
|
1402
|
+
});
|
|
1403
|
+
const transformed = await resolve_opts.transformPageChunk({
|
|
1404
|
+
html,
|
|
1405
|
+
done: true
|
|
1406
|
+
}) || "";
|
|
1407
|
+
if (!chunks) headers2.set("etag", `"${hash(transformed)}"`);
|
|
1408
|
+
return chunks ? new Response(stream_text(transformed + "\n", chunks), {
|
|
1409
|
+
status,
|
|
1410
|
+
headers: headers2
|
|
1411
|
+
}) : text(transformed, {
|
|
1412
|
+
status,
|
|
1413
|
+
headers: headers2
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
var Head = class {
|
|
1417
|
+
#rendered;
|
|
1418
|
+
/** @type {string[]} */
|
|
1419
|
+
#http_equiv = [];
|
|
1420
|
+
/** @type {string[]} */
|
|
1421
|
+
#link_tags = [];
|
|
1422
|
+
/** @type {string[]} */
|
|
1423
|
+
#style_tags = [];
|
|
1424
|
+
/** @type {string[]} */
|
|
1425
|
+
#stylesheet_links = [];
|
|
1426
|
+
/**
|
|
1427
|
+
* @param {string} rendered
|
|
1428
|
+
*/
|
|
1429
|
+
constructor(rendered) {
|
|
1430
|
+
this.#rendered = rendered;
|
|
1431
|
+
}
|
|
1432
|
+
build() {
|
|
1433
|
+
return [
|
|
1434
|
+
...this.#http_equiv,
|
|
1435
|
+
...this.#link_tags,
|
|
1436
|
+
this.#rendered,
|
|
1437
|
+
...this.#style_tags,
|
|
1438
|
+
...this.#stylesheet_links
|
|
1439
|
+
].join("\n ");
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* @param {string} style
|
|
1443
|
+
* @param {string[]} attributes
|
|
1444
|
+
*/
|
|
1445
|
+
add_style(style, attributes) {
|
|
1446
|
+
this.#style_tags.push(`<style${attributes.length ? " " + attributes.join(" ") : ""}>${style}</style>`);
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* @param {string} href
|
|
1450
|
+
* @param {string[]} attributes
|
|
1451
|
+
*/
|
|
1452
|
+
add_stylesheet(href, attributes) {
|
|
1453
|
+
this.#stylesheet_links.push(`<link href="${href}" ${attributes.join(" ")}>`);
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* @param {string} href
|
|
1457
|
+
* @param {string[]} attributes
|
|
1458
|
+
*/
|
|
1459
|
+
add_link_tag(href, attributes) {
|
|
1460
|
+
this.#link_tags.push(`<link href="${href}" ${attributes.join(" ")}>`);
|
|
1461
|
+
}
|
|
1462
|
+
/** @param {string} tag */
|
|
1463
|
+
add_http_equiv(tag) {
|
|
1464
|
+
this.#http_equiv.push(tag);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
function join_or(items) {
|
|
1468
|
+
return items.length > 1 ? `${items.slice(0, -1).join(", ")} or ${items.at(-1)}` : items[0];
|
|
1469
|
+
}
|
|
1470
|
+
function validator(expected) {
|
|
1471
|
+
function validate(module, file) {
|
|
1472
|
+
if (!module) return;
|
|
1473
|
+
for (const key in module) {
|
|
1474
|
+
if (key[0] === "_" || expected.has(key)) continue;
|
|
1475
|
+
const locations = valid_locations(key, file?.slice(file.lastIndexOf(".")));
|
|
1476
|
+
if (locations.length > 0) invalid_export_location({
|
|
1477
|
+
key,
|
|
1478
|
+
locations: join_or(locations),
|
|
1479
|
+
file: file || void 0
|
|
1480
|
+
});
|
|
1481
|
+
invalid_export({
|
|
1482
|
+
key,
|
|
1483
|
+
exports: [...expected.values()].join(", "),
|
|
1484
|
+
file: file || void 0
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
return validate;
|
|
1489
|
+
}
|
|
1490
|
+
function valid_locations(key, ext = ".js") {
|
|
1491
|
+
const locations = [];
|
|
1492
|
+
if (valid_layout_exports.has(key)) locations.push(`+layout${ext}`);
|
|
1493
|
+
if (valid_page_exports.has(key)) locations.push(`+page${ext}`);
|
|
1494
|
+
if (valid_layout_server_exports.has(key)) locations.push(`+layout.server${ext}`);
|
|
1495
|
+
if (valid_page_server_exports.has(key)) locations.push(`+page.server${ext}`);
|
|
1496
|
+
if (valid_server_exports.has(key)) locations.push(`+server${ext}`);
|
|
1497
|
+
return locations;
|
|
1498
|
+
}
|
|
1499
|
+
var valid_layout_exports = /* @__PURE__ */ new Set([
|
|
1500
|
+
"load",
|
|
1501
|
+
"prerender",
|
|
1502
|
+
"csr",
|
|
1503
|
+
"ssr",
|
|
1504
|
+
"trailingSlash",
|
|
1505
|
+
"config"
|
|
1506
|
+
]);
|
|
1507
|
+
var valid_page_exports = /* @__PURE__ */ new Set([...valid_layout_exports, "entries"]);
|
|
1508
|
+
var valid_layout_server_exports = /* @__PURE__ */ new Set([...valid_layout_exports]);
|
|
1509
|
+
var valid_page_server_exports = /* @__PURE__ */ new Set([
|
|
1510
|
+
...valid_layout_server_exports,
|
|
1511
|
+
"actions",
|
|
1512
|
+
"entries"
|
|
1513
|
+
]);
|
|
1514
|
+
var valid_server_exports = /* @__PURE__ */ new Set([
|
|
1515
|
+
"GET",
|
|
1516
|
+
"POST",
|
|
1517
|
+
"PATCH",
|
|
1518
|
+
"PUT",
|
|
1519
|
+
"DELETE",
|
|
1520
|
+
"OPTIONS",
|
|
1521
|
+
"HEAD",
|
|
1522
|
+
"QUERY",
|
|
1523
|
+
"fallback",
|
|
1524
|
+
"prerender",
|
|
1525
|
+
"trailingSlash",
|
|
1526
|
+
"config",
|
|
1527
|
+
"entries"
|
|
1528
|
+
]);
|
|
1529
|
+
var validate_layout_exports = validator(valid_layout_exports);
|
|
1530
|
+
var validate_page_exports = validator(valid_page_exports);
|
|
1531
|
+
var validate_layout_server_exports = validator(valid_layout_server_exports);
|
|
1532
|
+
var validate_page_server_exports = validator(valid_page_server_exports);
|
|
1533
|
+
var PageNodes = class {
|
|
1534
|
+
/** All layout nodes and the page node, if any */
|
|
1535
|
+
data;
|
|
1536
|
+
/**
|
|
1537
|
+
* @param {Array<import('types').SSRNode | undefined>} nodes
|
|
1538
|
+
*/
|
|
1539
|
+
constructor(nodes) {
|
|
1540
|
+
this.data = nodes;
|
|
1541
|
+
}
|
|
1542
|
+
layouts() {
|
|
1543
|
+
return this.data.slice(0, -1);
|
|
1544
|
+
}
|
|
1545
|
+
page() {
|
|
1546
|
+
return this.data.at(-1);
|
|
1547
|
+
}
|
|
1548
|
+
validate() {
|
|
1549
|
+
for (const layout of this.layouts()) if (layout) {
|
|
1550
|
+
validate_layout_server_exports(layout.server, layout.server_id);
|
|
1551
|
+
validate_layout_exports(layout.universal, layout.universal_id);
|
|
1552
|
+
}
|
|
1553
|
+
const page = this.page();
|
|
1554
|
+
if (page) {
|
|
1555
|
+
validate_page_server_exports(page.server, page.server_id);
|
|
1556
|
+
validate_page_exports(page.universal, page.universal_id);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
1561
|
+
* @param {Option} option
|
|
1562
|
+
* @returns {(UniversalNode | ServerNode)[Option] | undefined}
|
|
1563
|
+
*/
|
|
1564
|
+
#get_option(option) {
|
|
1565
|
+
return this.data.reduce((value, node) => {
|
|
1566
|
+
return node?.universal?.[option] ?? node?.server?.[option] ?? value;
|
|
1567
|
+
}, void 0);
|
|
1568
|
+
}
|
|
1569
|
+
csr() {
|
|
1570
|
+
return this.#get_option("csr") ?? true;
|
|
1571
|
+
}
|
|
1572
|
+
ssr() {
|
|
1573
|
+
return this.#get_option("ssr") ?? true;
|
|
1574
|
+
}
|
|
1575
|
+
prerender() {
|
|
1576
|
+
return this.#get_option("prerender") ?? false;
|
|
1577
|
+
}
|
|
1578
|
+
trailing_slash() {
|
|
1579
|
+
return this.#get_option("trailingSlash") ?? "never";
|
|
1580
|
+
}
|
|
1581
|
+
get_config() {
|
|
1582
|
+
let current = {};
|
|
1583
|
+
for (const node of this.data) {
|
|
1584
|
+
if (!node?.universal?.config && !node?.server?.config) continue;
|
|
1585
|
+
current = {
|
|
1586
|
+
...current,
|
|
1587
|
+
...node?.server?.config,
|
|
1588
|
+
...node?.universal?.config
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
return Object.keys(current).length ? current : void 0;
|
|
1592
|
+
}
|
|
1593
|
+
should_prerender_data() {
|
|
1594
|
+
return this.data.some((node) => node?.server?.load || node?.server?.trailingSlash !== void 0);
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
async function respond_with_error({ event, state, error, resolve_opts }) {
|
|
1598
|
+
if (event.request.headers.get("x-sveltekit-error")) {
|
|
1599
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
1600
|
+
return static_error_page(transformed.status, transformed.message);
|
|
1601
|
+
}
|
|
1602
|
+
const fetched = [];
|
|
1603
|
+
try {
|
|
1604
|
+
const branch = [];
|
|
1605
|
+
const default_layout = await manifest.nodes[0]();
|
|
1606
|
+
const nodes = new PageNodes([default_layout]);
|
|
1607
|
+
const ssr = nodes.ssr();
|
|
1608
|
+
const csr = nodes.csr();
|
|
1609
|
+
const data_serializer = server_data_serializer(event, state);
|
|
1610
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
1611
|
+
if (ssr) {
|
|
1612
|
+
state.error = true;
|
|
1613
|
+
const server_data_promise = load_server_data({
|
|
1614
|
+
event,
|
|
1615
|
+
state,
|
|
1616
|
+
node: default_layout,
|
|
1617
|
+
parent: async () => ({})
|
|
1618
|
+
});
|
|
1619
|
+
const server_data = await server_data_promise;
|
|
1620
|
+
data_serializer.add_node(0, server_data);
|
|
1621
|
+
const data = await load_data({
|
|
1622
|
+
event,
|
|
1623
|
+
state,
|
|
1624
|
+
fetched,
|
|
1625
|
+
node: default_layout,
|
|
1626
|
+
parent: async () => ({}),
|
|
1627
|
+
resolve_opts,
|
|
1628
|
+
server_data_promise,
|
|
1629
|
+
csr
|
|
1630
|
+
});
|
|
1631
|
+
branch.push({
|
|
1632
|
+
node: default_layout,
|
|
1633
|
+
server_data,
|
|
1634
|
+
data
|
|
1635
|
+
}, {
|
|
1636
|
+
node: await manifest.nodes[1](),
|
|
1637
|
+
data: null,
|
|
1638
|
+
server_data: null
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
return await render_response({
|
|
1642
|
+
page_config: {
|
|
1643
|
+
ssr,
|
|
1644
|
+
csr
|
|
1645
|
+
},
|
|
1646
|
+
status: transformed.status,
|
|
1647
|
+
error: transformed,
|
|
1648
|
+
branch,
|
|
1649
|
+
error_components: [],
|
|
1650
|
+
fetched,
|
|
1651
|
+
event,
|
|
1652
|
+
state,
|
|
1653
|
+
resolve_opts,
|
|
1654
|
+
data_serializer
|
|
1655
|
+
});
|
|
1656
|
+
} catch (e) {
|
|
1657
|
+
if (e instanceof Redirect) return redirect_response(e.status, e.location);
|
|
1658
|
+
const transformed = await handle_error_and_jsonify(event, state, e);
|
|
1659
|
+
return static_error_page(transformed.status, transformed.message);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function static_error_page(status, message) {
|
|
1663
|
+
let page = options.templates.error({
|
|
1664
|
+
status,
|
|
1665
|
+
message: escape_html2(message)
|
|
1666
|
+
});
|
|
1667
|
+
return text(page, {
|
|
1668
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
1669
|
+
status
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
async function handle_fatal_error(event, state, error) {
|
|
1673
|
+
const body = await handle_error_and_jsonify(event, state, error);
|
|
1674
|
+
const status = body.status;
|
|
1675
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", ["application/json", "text/html"]);
|
|
1676
|
+
if (event.isDataRequest || type === "application/json") return Response.json(body, { status });
|
|
1677
|
+
return static_error_page(status, body.message);
|
|
1678
|
+
}
|
|
1679
|
+
var MAX_DEPTH = 10;
|
|
1680
|
+
async function render_page(event, state, page, nodes, resolve_opts) {
|
|
1681
|
+
if (state.depth > MAX_DEPTH) return text(`Not found: ${event.url.pathname}`, { status: 404 });
|
|
1682
|
+
if (is_action_json_request(event)) {
|
|
1683
|
+
const node = await manifest.nodes[page.leaf]();
|
|
1684
|
+
return handle_action_json_request(event, state, node?.server);
|
|
1685
|
+
}
|
|
1686
|
+
try {
|
|
1687
|
+
const leaf_node = nodes.page();
|
|
1688
|
+
let status = 200;
|
|
1689
|
+
let action_result = void 0;
|
|
1690
|
+
if (is_action_request(event)) {
|
|
1691
|
+
const remote_id = get_remote_action(event.url);
|
|
1692
|
+
if (remote_id) action_result = await handle_remote_form_post(event, state, remote_id);
|
|
1693
|
+
else action_result = await handle_action_request(event, state, leaf_node.server);
|
|
1694
|
+
if (action_result?.type === "redirect") return redirect_response(action_result.status, action_result.location);
|
|
1695
|
+
if (action_result?.type === "error") status = get_status(action_result.error);
|
|
1696
|
+
if (action_result?.type === "failure") status = action_result.status;
|
|
1697
|
+
}
|
|
1698
|
+
const should_prerender = nodes.prerender();
|
|
1699
|
+
if (should_prerender) {
|
|
1700
|
+
if (leaf_node.server?.actions) prerender_actions();
|
|
1701
|
+
} else if (state.prerendering) return new Response(void 0, { status: 204 });
|
|
1702
|
+
state.prerender_default = should_prerender;
|
|
1703
|
+
const should_prerender_data = nodes.should_prerender_data();
|
|
1704
|
+
const data_pathname = add_data_suffix(event.url.pathname);
|
|
1705
|
+
const fetched = [];
|
|
1706
|
+
const ssr = nodes.ssr();
|
|
1707
|
+
const csr = nodes.csr();
|
|
1708
|
+
if (ssr === false && !((state.prerendering || state.prerender_default === true) && should_prerender_data)) return await render_response({
|
|
1709
|
+
branch: compact(nodes.data).map((node) => {
|
|
1710
|
+
return {
|
|
1711
|
+
node,
|
|
1712
|
+
data: null,
|
|
1713
|
+
server_data: null
|
|
1714
|
+
};
|
|
1715
|
+
}),
|
|
1716
|
+
fetched,
|
|
1717
|
+
page_config: {
|
|
1718
|
+
ssr: false,
|
|
1719
|
+
csr
|
|
1720
|
+
},
|
|
1721
|
+
status,
|
|
1722
|
+
error: null,
|
|
1723
|
+
event,
|
|
1724
|
+
state,
|
|
1725
|
+
resolve_opts,
|
|
1726
|
+
data_serializer: server_data_serializer(event, state)
|
|
1727
|
+
});
|
|
1728
|
+
const branch = [];
|
|
1729
|
+
let load_error = null;
|
|
1730
|
+
const data_serializer = server_data_serializer(event, state);
|
|
1731
|
+
const data_serializer_json = (state.prerendering || state.prerender_default === true) && should_prerender_data ? server_data_serializer_json(event, state) : null;
|
|
1732
|
+
const server_promises = nodes.data.map((node, i) => {
|
|
1733
|
+
if (load_error) throw load_error;
|
|
1734
|
+
return Promise.resolve().then(async () => {
|
|
1735
|
+
try {
|
|
1736
|
+
if (node === leaf_node && action_result?.type === "error") throw action_result.error;
|
|
1737
|
+
const server_data = await load_server_data({
|
|
1738
|
+
event,
|
|
1739
|
+
state,
|
|
1740
|
+
node,
|
|
1741
|
+
parent: async () => {
|
|
1742
|
+
const data = {};
|
|
1743
|
+
for (let j = 0; j < i; j += 1) {
|
|
1744
|
+
const parent = await server_promises[j];
|
|
1745
|
+
if (parent) Object.assign(data, parent.data);
|
|
1746
|
+
}
|
|
1747
|
+
return data;
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
if (node) data_serializer.add_node(i, server_data);
|
|
1751
|
+
data_serializer_json?.add_node(i, server_data);
|
|
1752
|
+
return server_data;
|
|
1753
|
+
} catch (e) {
|
|
1754
|
+
load_error = e;
|
|
1755
|
+
throw load_error;
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
});
|
|
1759
|
+
const load_promises = nodes.data.map((node, i) => {
|
|
1760
|
+
if (load_error) throw load_error;
|
|
1761
|
+
return Promise.resolve().then(async () => {
|
|
1762
|
+
try {
|
|
1763
|
+
return await load_data({
|
|
1764
|
+
event,
|
|
1765
|
+
state,
|
|
1766
|
+
fetched,
|
|
1767
|
+
node,
|
|
1768
|
+
parent: async () => {
|
|
1769
|
+
const data = {};
|
|
1770
|
+
for (let j = 0; j < i; j += 1) Object.assign(data, await load_promises[j]);
|
|
1771
|
+
return data;
|
|
1772
|
+
},
|
|
1773
|
+
resolve_opts,
|
|
1774
|
+
server_data_promise: server_promises[i],
|
|
1775
|
+
csr
|
|
1776
|
+
});
|
|
1777
|
+
} catch (e) {
|
|
1778
|
+
load_error = e;
|
|
1779
|
+
throw load_error;
|
|
1780
|
+
}
|
|
1781
|
+
});
|
|
1782
|
+
});
|
|
1783
|
+
for (const p of server_promises) p.catch(noop);
|
|
1784
|
+
for (const p of load_promises) p.catch(noop);
|
|
1785
|
+
for (let i = 0; i < nodes.data.length; i += 1) {
|
|
1786
|
+
const node = nodes.data[i];
|
|
1787
|
+
if (node) try {
|
|
1788
|
+
const server_data = await server_promises[i];
|
|
1789
|
+
const data = await load_promises[i];
|
|
1790
|
+
branch.push({
|
|
1791
|
+
node,
|
|
1792
|
+
server_data,
|
|
1793
|
+
data
|
|
1794
|
+
});
|
|
1795
|
+
} catch (e) {
|
|
1796
|
+
const err = normalize_error(e);
|
|
1797
|
+
if (err instanceof Redirect) {
|
|
1798
|
+
if (state.prerendering && should_prerender_data) {
|
|
1799
|
+
const body = JSON.stringify({
|
|
1800
|
+
type: "redirect",
|
|
1801
|
+
status: err.status,
|
|
1802
|
+
location: err.location
|
|
1803
|
+
});
|
|
1804
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
1805
|
+
response: text(body),
|
|
1806
|
+
body
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
return redirect_response(err.status, err.location);
|
|
1810
|
+
}
|
|
1811
|
+
const error = await handle_error_and_jsonify(event, state, err);
|
|
1812
|
+
const status2 = error.status;
|
|
1813
|
+
for (const { error: index, idx } of nearest_error_pages(i, branch, page.errors)) {
|
|
1814
|
+
const node2 = await manifest.nodes[index]();
|
|
1815
|
+
data_serializer.set_max_nodes(idx);
|
|
1816
|
+
const layouts = compact(branch.slice(0, idx));
|
|
1817
|
+
const nodes2 = new PageNodes(layouts.map((layout) => layout.node));
|
|
1818
|
+
const error_branch = layouts.concat({
|
|
1819
|
+
node: node2,
|
|
1820
|
+
data: null,
|
|
1821
|
+
server_data: null
|
|
1822
|
+
});
|
|
1823
|
+
return await render_response({
|
|
1824
|
+
event,
|
|
1825
|
+
state,
|
|
1826
|
+
resolve_opts,
|
|
1827
|
+
page_config: {
|
|
1828
|
+
ssr: nodes2.ssr(),
|
|
1829
|
+
csr: nodes2.csr()
|
|
1830
|
+
},
|
|
1831
|
+
status: status2,
|
|
1832
|
+
error,
|
|
1833
|
+
error_components: await load_error_components(ssr, error_branch, page),
|
|
1834
|
+
branch: error_branch,
|
|
1835
|
+
fetched,
|
|
1836
|
+
data_serializer
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
return static_error_page(status2, error.message);
|
|
1840
|
+
}
|
|
1841
|
+
else branch.push(null);
|
|
1842
|
+
}
|
|
1843
|
+
if (state.prerendering && data_serializer_json) {
|
|
1844
|
+
let { data, chunks } = data_serializer_json.get_data();
|
|
1845
|
+
if (chunks) for await (const chunk of chunks) data += chunk;
|
|
1846
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
1847
|
+
response: text(data),
|
|
1848
|
+
body: data
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
return await render_response({
|
|
1852
|
+
event,
|
|
1853
|
+
state,
|
|
1854
|
+
resolve_opts,
|
|
1855
|
+
page_config: {
|
|
1856
|
+
csr,
|
|
1857
|
+
ssr
|
|
1858
|
+
},
|
|
1859
|
+
status,
|
|
1860
|
+
error: null,
|
|
1861
|
+
branch: compact(branch),
|
|
1862
|
+
action_result,
|
|
1863
|
+
fetched,
|
|
1864
|
+
data_serializer: !ssr ? server_data_serializer(event, state) : data_serializer,
|
|
1865
|
+
error_components: await load_error_components(ssr, branch, page)
|
|
1866
|
+
});
|
|
1867
|
+
} catch (e) {
|
|
1868
|
+
if (e instanceof Redirect) return redirect_response(e.status, e.location);
|
|
1869
|
+
return await respond_with_error({
|
|
1870
|
+
event,
|
|
1871
|
+
state,
|
|
1872
|
+
error: e,
|
|
1873
|
+
resolve_opts
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
function load_error_components(ssr, branch, page) {
|
|
1878
|
+
if (!ssr) return void 0;
|
|
1879
|
+
return build_error_chain(branch, page.errors, (idx) => manifest.nodes[idx]?.().then((e) => e.component?.()));
|
|
1880
|
+
}
|
|
1881
|
+
var mutating_form_methods = /* @__PURE__ */ new Set([
|
|
1882
|
+
"POST",
|
|
1883
|
+
"PUT",
|
|
1884
|
+
"PATCH",
|
|
1885
|
+
"DELETE"
|
|
1886
|
+
]);
|
|
1887
|
+
function get_self_origin(paths_origin, url_origin) {
|
|
1888
|
+
return paths_origin || url_origin;
|
|
1889
|
+
}
|
|
1890
|
+
function is_csrf_forbidden({ request, request_origin, self_origin, trusted_origins }) {
|
|
1891
|
+
return (!request.headers.get("content-type") || is_form_content_type(request)) && mutating_form_methods.has(request.method) && request_origin !== self_origin && (!request_origin || !trusted_origins.includes(request_origin));
|
|
1892
|
+
}
|
|
1893
|
+
function is_remote_forbidden({ request, request_origin, self_origin }) {
|
|
1894
|
+
return request.method !== "GET" && request_origin !== self_origin;
|
|
1895
|
+
}
|
|
1896
|
+
async function render_data(event, state, route, invalidated_data_nodes, trailing_slash) {
|
|
1897
|
+
if (!route.page) return with_version_header(new Response(void 0, { status: 404 }));
|
|
1898
|
+
try {
|
|
1899
|
+
const node_ids = [...route.page.layouts, route.page.leaf];
|
|
1900
|
+
const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
|
|
1901
|
+
let aborted = false;
|
|
1902
|
+
const url = new URL(event.url);
|
|
1903
|
+
url.pathname = normalize_path(url.pathname, trailing_slash);
|
|
1904
|
+
const new_event = {
|
|
1905
|
+
...event,
|
|
1906
|
+
url
|
|
1907
|
+
};
|
|
1908
|
+
const functions = node_ids.map((n, i) => {
|
|
1909
|
+
return once(async () => {
|
|
1910
|
+
try {
|
|
1911
|
+
if (aborted) return { type: "skip" };
|
|
1912
|
+
const node = n == void 0 ? n : await manifest.nodes[n]();
|
|
1913
|
+
return load_server_data({
|
|
1914
|
+
event: new_event,
|
|
1915
|
+
state,
|
|
1916
|
+
node,
|
|
1917
|
+
parent: async () => {
|
|
1918
|
+
const data2 = {};
|
|
1919
|
+
for (let j = 0; j < i; j += 1) {
|
|
1920
|
+
const parent = await functions[j]();
|
|
1921
|
+
if (parent) Object.assign(data2, parent.data);
|
|
1922
|
+
}
|
|
1923
|
+
return data2;
|
|
1924
|
+
}
|
|
1925
|
+
});
|
|
1926
|
+
} catch (e) {
|
|
1927
|
+
aborted = true;
|
|
1928
|
+
throw e;
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
});
|
|
1932
|
+
const promises = functions.map(async (fn, i) => {
|
|
1933
|
+
if (!invalidated[i]) return { type: "skip" };
|
|
1934
|
+
return fn();
|
|
1935
|
+
});
|
|
1936
|
+
const data_serializer = server_data_serializer_json(event, state);
|
|
1937
|
+
await Promise.all(promises.map(async (p, i) => {
|
|
1938
|
+
const node = await p.catch(async (error) => {
|
|
1939
|
+
if (error instanceof Redirect) throw error;
|
|
1940
|
+
return {
|
|
1941
|
+
type: "error",
|
|
1942
|
+
error: await handle_error_and_jsonify(event, state, error)
|
|
1943
|
+
};
|
|
1944
|
+
});
|
|
1945
|
+
data_serializer.add_node(i, node);
|
|
1946
|
+
}));
|
|
1947
|
+
const { data, chunks } = data_serializer.get_data();
|
|
1948
|
+
if (!chunks) return json_response(data);
|
|
1949
|
+
return with_version_header(new Response(stream_text(data, chunks), { headers: {
|
|
1950
|
+
"content-type": "text/sveltekit-data",
|
|
1951
|
+
"cache-control": "private, no-store"
|
|
1952
|
+
} }));
|
|
1953
|
+
} catch (e) {
|
|
1954
|
+
const error = normalize_error(e);
|
|
1955
|
+
if (error instanceof Redirect) return redirect_json_response(error);
|
|
1956
|
+
else {
|
|
1957
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
1958
|
+
return json_response(transformed, transformed.status);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
function json_response(json, status = 200) {
|
|
1963
|
+
return with_version_header(text(typeof json === "string" ? json : JSON.stringify(json), {
|
|
1964
|
+
status,
|
|
1965
|
+
headers: {
|
|
1966
|
+
"content-type": "application/json",
|
|
1967
|
+
"cache-control": "private, no-store"
|
|
1968
|
+
}
|
|
1969
|
+
}));
|
|
1970
|
+
}
|
|
1971
|
+
function redirect_json_response(redirect) {
|
|
1972
|
+
return json_response({
|
|
1973
|
+
type: "redirect",
|
|
1974
|
+
status: redirect.status,
|
|
1975
|
+
location: redirect.location
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
var cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
|
|
1979
|
+
var cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
|
|
1980
|
+
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
1981
|
+
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
1982
|
+
var maxAgeRegExp = /^-?\d+$/;
|
|
1983
|
+
var cookieOctetRegExp = /^[!#$&'()*+\-.\/0-9:<=>?@A-Z[\]\^_`a-z{|}~]*$/;
|
|
1984
|
+
var NullObject = /* @__PURE__ */ (() => {
|
|
1985
|
+
const C = function() {
|
|
1986
|
+
};
|
|
1987
|
+
C.prototype = /* @__PURE__ */ Object.create(null);
|
|
1988
|
+
return C;
|
|
1989
|
+
})();
|
|
1990
|
+
function parseCookie(str, options2) {
|
|
1991
|
+
const obj = new NullObject();
|
|
1992
|
+
const len = str.length;
|
|
1993
|
+
if (len < 2) return obj;
|
|
1994
|
+
const dec = options2?.decode || decode;
|
|
1995
|
+
let index = 0;
|
|
1996
|
+
do {
|
|
1997
|
+
const eqIdx = eqIndex(str, index, len);
|
|
1998
|
+
if (eqIdx === len) break;
|
|
1999
|
+
const endIdx = endIndex(str, index, len);
|
|
2000
|
+
if (eqIdx > endIdx) {
|
|
2001
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
2002
|
+
continue;
|
|
2003
|
+
}
|
|
2004
|
+
const key = valueSlice(str, index, eqIdx);
|
|
2005
|
+
if (obj[key] === void 0) obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
|
|
2006
|
+
index = endIdx + 1;
|
|
2007
|
+
} while (index < len);
|
|
2008
|
+
return obj;
|
|
2009
|
+
}
|
|
2010
|
+
function stringifySetCookie(cookie, options2) {
|
|
2011
|
+
const enc = options2?.encode || defaultEncode;
|
|
2012
|
+
if (!cookieNameRegExp.test(cookie.name)) throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
2013
|
+
const value = cookie.value == null ? "" : enc(cookie.value);
|
|
2014
|
+
if (!cookieValueRegExp.test(value)) throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
2015
|
+
let str = cookie.name + "=" + value;
|
|
2016
|
+
if (cookie.maxAge !== void 0) {
|
|
2017
|
+
if (!Number.isInteger(cookie.maxAge)) throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
2018
|
+
str += "; Max-Age=" + cookie.maxAge;
|
|
2019
|
+
}
|
|
2020
|
+
if (cookie.domain) {
|
|
2021
|
+
if (!domainValueRegExp.test(cookie.domain)) throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
2022
|
+
str += "; Domain=" + cookie.domain;
|
|
2023
|
+
}
|
|
2024
|
+
if (cookie.path) {
|
|
2025
|
+
if (!pathValueRegExp.test(cookie.path)) throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
2026
|
+
str += "; Path=" + cookie.path;
|
|
2027
|
+
}
|
|
2028
|
+
if (cookie.expires) {
|
|
2029
|
+
if (!Number.isFinite(cookie.expires.valueOf())) throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
2030
|
+
str += "; Expires=" + cookie.expires.toUTCString();
|
|
2031
|
+
}
|
|
2032
|
+
if (cookie.httpOnly) str += "; HttpOnly";
|
|
2033
|
+
if (cookie.secure) str += "; Secure";
|
|
2034
|
+
if (cookie.partitioned) str += "; Partitioned";
|
|
2035
|
+
if (cookie.priority) switch (typeof cookie.priority === "string" ? cookie.priority.toLowerCase() : void 0) {
|
|
2036
|
+
case "low":
|
|
2037
|
+
str += "; Priority=Low";
|
|
2038
|
+
break;
|
|
2039
|
+
case "medium":
|
|
2040
|
+
str += "; Priority=Medium";
|
|
2041
|
+
break;
|
|
2042
|
+
case "high":
|
|
2043
|
+
str += "; Priority=High";
|
|
2044
|
+
break;
|
|
2045
|
+
default:
|
|
2046
|
+
throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
2047
|
+
}
|
|
2048
|
+
if (cookie.sameSite) switch (typeof cookie.sameSite === "string" ? cookie.sameSite.toLowerCase() : cookie.sameSite) {
|
|
2049
|
+
case true:
|
|
2050
|
+
case "strict":
|
|
2051
|
+
str += "; SameSite=Strict";
|
|
2052
|
+
break;
|
|
2053
|
+
case "lax":
|
|
2054
|
+
str += "; SameSite=Lax";
|
|
2055
|
+
break;
|
|
2056
|
+
case "none":
|
|
2057
|
+
str += "; SameSite=None";
|
|
2058
|
+
break;
|
|
2059
|
+
default:
|
|
2060
|
+
throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
2061
|
+
}
|
|
2062
|
+
return str;
|
|
2063
|
+
}
|
|
2064
|
+
function parseSetCookie(str, options2) {
|
|
2065
|
+
const dec = options2?.decode || decode;
|
|
2066
|
+
const len = str.length;
|
|
2067
|
+
const endIdx = endIndex(str, 0, len);
|
|
2068
|
+
let eqIdx = eqIndex(str, 0, len);
|
|
2069
|
+
const setCookie = eqIdx < endIdx ? {
|
|
2070
|
+
name: valueSlice(str, 0, eqIdx),
|
|
2071
|
+
value: dec(valueSlice(str, eqIdx + 1, endIdx))
|
|
2072
|
+
} : {
|
|
2073
|
+
name: "",
|
|
2074
|
+
value: dec(valueSlice(str, 0, endIdx))
|
|
2075
|
+
};
|
|
2076
|
+
let index = endIdx + 1;
|
|
2077
|
+
while (index < len) {
|
|
2078
|
+
const endIdx2 = endIndex(str, index, len);
|
|
2079
|
+
if (eqIdx < index) eqIdx = eqIndex(str, index, len);
|
|
2080
|
+
const attr = eqIdx < endIdx2 ? valueSlice(str, index, eqIdx) : valueSlice(str, index, endIdx2);
|
|
2081
|
+
const val = eqIdx < endIdx2 ? valueSlice(str, eqIdx + 1, endIdx2) : void 0;
|
|
2082
|
+
switch (attr.toLowerCase()) {
|
|
2083
|
+
case "httponly":
|
|
2084
|
+
setCookie.httpOnly = true;
|
|
2085
|
+
break;
|
|
2086
|
+
case "secure":
|
|
2087
|
+
setCookie.secure = true;
|
|
2088
|
+
break;
|
|
2089
|
+
case "partitioned":
|
|
2090
|
+
setCookie.partitioned = true;
|
|
2091
|
+
break;
|
|
2092
|
+
case "domain":
|
|
2093
|
+
setCookie.domain = val;
|
|
2094
|
+
break;
|
|
2095
|
+
case "path":
|
|
2096
|
+
setCookie.path = val;
|
|
2097
|
+
break;
|
|
2098
|
+
case "max-age":
|
|
2099
|
+
if (val && maxAgeRegExp.test(val)) setCookie.maxAge = Number(val);
|
|
2100
|
+
break;
|
|
2101
|
+
case "expires":
|
|
2102
|
+
if (!val) break;
|
|
2103
|
+
const date = new Date(val);
|
|
2104
|
+
if (Number.isFinite(date.valueOf())) setCookie.expires = date;
|
|
2105
|
+
break;
|
|
2106
|
+
case "priority":
|
|
2107
|
+
if (!val) break;
|
|
2108
|
+
const priority = val.toLowerCase();
|
|
2109
|
+
if (priority === "low" || priority === "medium" || priority === "high") setCookie.priority = priority;
|
|
2110
|
+
break;
|
|
2111
|
+
case "samesite":
|
|
2112
|
+
if (!val) break;
|
|
2113
|
+
const sameSite = val.toLowerCase();
|
|
2114
|
+
if (sameSite === "lax" || sameSite === "strict" || sameSite === "none") setCookie.sameSite = sameSite;
|
|
2115
|
+
}
|
|
2116
|
+
index = endIdx2 + 1;
|
|
2117
|
+
}
|
|
2118
|
+
return setCookie;
|
|
2119
|
+
}
|
|
2120
|
+
function endIndex(str, min, len) {
|
|
2121
|
+
const index = str.indexOf(";", min);
|
|
2122
|
+
return index === -1 ? len : index;
|
|
2123
|
+
}
|
|
2124
|
+
function eqIndex(str, min, len) {
|
|
2125
|
+
const index = str.indexOf("=", min);
|
|
2126
|
+
return index === -1 ? len : index;
|
|
2127
|
+
}
|
|
2128
|
+
function valueSlice(str, min, max) {
|
|
2129
|
+
if (min === max) return "";
|
|
2130
|
+
let start = min;
|
|
2131
|
+
let end = max;
|
|
2132
|
+
do {
|
|
2133
|
+
const code = str.charCodeAt(start);
|
|
2134
|
+
if (code !== 32 && code !== 9) break;
|
|
2135
|
+
} while (++start < end);
|
|
2136
|
+
while (end > start) {
|
|
2137
|
+
const code = str.charCodeAt(end - 1);
|
|
2138
|
+
if (code !== 32 && code !== 9) break;
|
|
2139
|
+
end--;
|
|
2140
|
+
}
|
|
2141
|
+
return str.slice(start, end);
|
|
2142
|
+
}
|
|
2143
|
+
function decode(str) {
|
|
2144
|
+
if (str.indexOf("%") === -1) return str;
|
|
2145
|
+
try {
|
|
2146
|
+
return decodeURIComponent(str);
|
|
2147
|
+
} catch (e) {
|
|
2148
|
+
return str;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
function defaultEncode(str) {
|
|
2152
|
+
return cookieOctetRegExp.test(str) ? str : encodeURIComponent(str);
|
|
2153
|
+
}
|
|
2154
|
+
function generate_cookie_key(domain, path, name) {
|
|
2155
|
+
return `${domain || ""}${path}?${encodeURIComponent(name)}`;
|
|
2156
|
+
}
|
|
2157
|
+
function get_cookies(request, url) {
|
|
2158
|
+
const header = request.headers.get("cookie") ?? "";
|
|
2159
|
+
const initial_cookies = parseCookie(header, { decode: (value) => value });
|
|
2160
|
+
let default_cookies;
|
|
2161
|
+
function parse_header(opts) {
|
|
2162
|
+
return opts?.decode ? parseCookie(header, opts) : default_cookies ??= parseCookie(header);
|
|
2163
|
+
}
|
|
2164
|
+
function matches_url(cookie) {
|
|
2165
|
+
return domain_matches(url.hostname, cookie.options.domain) && path_matches(url.pathname, cookie.options.path);
|
|
2166
|
+
}
|
|
2167
|
+
let normalized_url;
|
|
2168
|
+
const new_cookies = /* @__PURE__ */ new Map();
|
|
2169
|
+
const defaults = {
|
|
2170
|
+
httpOnly: true,
|
|
2171
|
+
path: "/",
|
|
2172
|
+
sameSite: "lax",
|
|
2173
|
+
secure: !(url.hostname === "localhost" && url.protocol === "http:")
|
|
2174
|
+
};
|
|
2175
|
+
const cookies = {
|
|
2176
|
+
get(name, opts) {
|
|
2177
|
+
let best_match;
|
|
2178
|
+
for (const c of new_cookies.values()) if (c.name === name && matches_url(c) && (!best_match || c.options.path.length > best_match.options.path.length)) best_match = c;
|
|
2179
|
+
if (best_match) return best_match.options.maxAge === 0 ? void 0 : best_match.value;
|
|
2180
|
+
return parse_header(opts)[name];
|
|
2181
|
+
},
|
|
2182
|
+
getAll(opts) {
|
|
2183
|
+
const cookies2 = { ...parse_header(opts) };
|
|
2184
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
2185
|
+
for (const c of new_cookies.values()) if (matches_url(c)) {
|
|
2186
|
+
const existing = lookup.get(c.name);
|
|
2187
|
+
if (!existing || c.options.path.length > existing.options.path.length) lookup.set(c.name, c);
|
|
2188
|
+
}
|
|
2189
|
+
for (const c of lookup.values()) if (c.options.maxAge === 0) delete cookies2[c.name];
|
|
2190
|
+
else cookies2[c.name] = c.value;
|
|
2191
|
+
return Object.entries(cookies2).filter(([, value]) => value != null).map(([name, value]) => ({
|
|
2192
|
+
name,
|
|
2193
|
+
value
|
|
2194
|
+
}));
|
|
2195
|
+
},
|
|
2196
|
+
set(name, value, options2) {
|
|
2197
|
+
set_internal(name, value, {
|
|
2198
|
+
...defaults,
|
|
2199
|
+
...options2
|
|
2200
|
+
});
|
|
2201
|
+
},
|
|
2202
|
+
delete(name, options2) {
|
|
2203
|
+
cookies.set(name, "", {
|
|
2204
|
+
...options2,
|
|
2205
|
+
maxAge: 0
|
|
2206
|
+
});
|
|
2207
|
+
},
|
|
2208
|
+
parse: parseSetCookie,
|
|
2209
|
+
serialize(name, value, { encode, ...options2 } = {}) {
|
|
2210
|
+
let path = options2.path ?? "/";
|
|
2211
|
+
if (!options2.domain || options2.domain === url.hostname) {
|
|
2212
|
+
if (!normalized_url) cookies_serialize_before_route();
|
|
2213
|
+
path = resolve(normalized_url, path);
|
|
2214
|
+
}
|
|
2215
|
+
return stringifySetCookie({
|
|
2216
|
+
name,
|
|
2217
|
+
value,
|
|
2218
|
+
...defaults,
|
|
2219
|
+
...options2,
|
|
2220
|
+
path
|
|
2221
|
+
}, { encode });
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
function get_cookie_header(destination, header2) {
|
|
2225
|
+
const combined_cookies = { ...initial_cookies };
|
|
2226
|
+
for (const cookie of new_cookies.values()) {
|
|
2227
|
+
if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
|
|
2228
|
+
if (!path_matches(destination.pathname, cookie.options.path)) continue;
|
|
2229
|
+
const encoder = cookie.options.encode || encodeURIComponent;
|
|
2230
|
+
combined_cookies[cookie.name] = encoder(cookie.value);
|
|
2231
|
+
}
|
|
2232
|
+
if (header2) {
|
|
2233
|
+
const parsed = parseCookie(header2, { decode: (value) => value });
|
|
2234
|
+
for (const name in parsed) combined_cookies[name] = parsed[name];
|
|
2235
|
+
}
|
|
2236
|
+
return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
|
|
2237
|
+
}
|
|
2238
|
+
const internal_queue = [];
|
|
2239
|
+
function set_internal(name, value, options2) {
|
|
2240
|
+
if (!normalized_url) {
|
|
2241
|
+
internal_queue.push(() => set_internal(name, value, options2));
|
|
2242
|
+
return;
|
|
2243
|
+
}
|
|
2244
|
+
let path = options2.path ?? "/";
|
|
2245
|
+
if (!options2.domain || options2.domain === url.hostname) path = resolve(normalized_url, path);
|
|
2246
|
+
const cookie_key = generate_cookie_key(options2.domain, path, name);
|
|
2247
|
+
const cookie = {
|
|
2248
|
+
name,
|
|
2249
|
+
value,
|
|
2250
|
+
options: {
|
|
2251
|
+
...options2,
|
|
2252
|
+
path
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
new_cookies.set(cookie_key, cookie);
|
|
2256
|
+
}
|
|
2257
|
+
function set_trailing_slash(trailing_slash) {
|
|
2258
|
+
normalized_url = normalize_path(url.pathname, trailing_slash);
|
|
2259
|
+
internal_queue.forEach((fn) => fn());
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
cookies,
|
|
2263
|
+
new_cookies,
|
|
2264
|
+
get_cookie_header,
|
|
2265
|
+
set_internal,
|
|
2266
|
+
set_trailing_slash
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
function domain_matches(hostname, constraint) {
|
|
2270
|
+
if (!constraint) return true;
|
|
2271
|
+
const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
|
|
2272
|
+
if (hostname === normalized) return true;
|
|
2273
|
+
return hostname.endsWith("." + normalized);
|
|
2274
|
+
}
|
|
2275
|
+
function path_matches(path, constraint) {
|
|
2276
|
+
if (!constraint) return true;
|
|
2277
|
+
const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
|
|
2278
|
+
if (path === normalized) return true;
|
|
2279
|
+
return path.startsWith(normalized + "/");
|
|
2280
|
+
}
|
|
2281
|
+
function add_cookies_to_headers(headers2, cookies) {
|
|
2282
|
+
for (const new_cookie of cookies) {
|
|
2283
|
+
const { name, value, options: { encode, ...options2 } } = new_cookie;
|
|
2284
|
+
headers2.append("set-cookie", stringifySetCookie({
|
|
2285
|
+
name,
|
|
2286
|
+
value,
|
|
2287
|
+
...options2
|
|
2288
|
+
}, { encode }));
|
|
2289
|
+
if (options2.path.endsWith(".html")) {
|
|
2290
|
+
const path = add_data_suffix(options2.path);
|
|
2291
|
+
headers2.append("set-cookie", stringifySetCookie({
|
|
2292
|
+
name,
|
|
2293
|
+
value,
|
|
2294
|
+
...options2,
|
|
2295
|
+
path
|
|
2296
|
+
}, { encode }));
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
function transient_fields() {
|
|
2301
|
+
return {
|
|
2302
|
+
remote: {
|
|
2303
|
+
data: null,
|
|
2304
|
+
explicit: null,
|
|
2305
|
+
implicit: null,
|
|
2306
|
+
forms: null,
|
|
2307
|
+
requested: null,
|
|
2308
|
+
ignored: null,
|
|
2309
|
+
batches: null,
|
|
2310
|
+
live_iterators: null
|
|
2311
|
+
},
|
|
2312
|
+
is_in_remote_function: false,
|
|
2313
|
+
is_in_remote_form_or_command: false,
|
|
2314
|
+
is_in_remote_query: false,
|
|
2315
|
+
is_in_remote_prerender: false,
|
|
2316
|
+
is_in_render: false
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
function create_request_state(options2) {
|
|
2320
|
+
return {
|
|
2321
|
+
getClientAddress: options2.getClientAddress,
|
|
2322
|
+
platform: options2.platform,
|
|
2323
|
+
read: options2.read,
|
|
2324
|
+
before_handle: options2.before_handle,
|
|
2325
|
+
emulator: options2.emulator,
|
|
2326
|
+
prerendering: options2.prerendering,
|
|
2327
|
+
prerender_default: void 0,
|
|
2328
|
+
error: false,
|
|
2329
|
+
depth: 0,
|
|
2330
|
+
rerouted_url: null,
|
|
2331
|
+
...transient_fields()
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
function fork_state_for_subrequest(state) {
|
|
2335
|
+
return {
|
|
2336
|
+
...state,
|
|
2337
|
+
...transient_fields(),
|
|
2338
|
+
depth: state.depth + 1
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
function create_fetch({ event, state, get_cookie_header, set_internal }) {
|
|
2342
|
+
const server_fetch = async (info, init2) => {
|
|
2343
|
+
const original_request = normalize_fetch_input(info, init2, event.url);
|
|
2344
|
+
let mode = (info instanceof Request ? info.mode : init2?.mode) ?? "cors";
|
|
2345
|
+
let credentials = (info instanceof Request ? info.credentials : init2?.credentials) ?? "same-origin";
|
|
2346
|
+
return hooks.handleFetch({
|
|
2347
|
+
event,
|
|
2348
|
+
request: original_request,
|
|
2349
|
+
fetch: async (info2, init3) => {
|
|
2350
|
+
const request = normalize_fetch_input(info2, init3, event.url);
|
|
2351
|
+
const url = new URL(request.url);
|
|
2352
|
+
if (!request.headers.has("origin")) request.headers.set("origin", event.url.origin);
|
|
2353
|
+
if (info2 !== original_request) {
|
|
2354
|
+
mode = (info2 instanceof Request ? info2.mode : init3?.mode) ?? "cors";
|
|
2355
|
+
credentials = (info2 instanceof Request ? info2.credentials : init3?.credentials) ?? "same-origin";
|
|
2356
|
+
}
|
|
2357
|
+
if ((request.method === "GET" || request.method === "HEAD") && (mode === "no-cors" && url.origin !== event.url.origin || url.origin === event.url.origin)) request.headers.delete("origin");
|
|
2358
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
2359
|
+
if (url.origin !== event.url.origin || "") {
|
|
2360
|
+
if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
|
|
2361
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
2362
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
2363
|
+
}
|
|
2364
|
+
return fetch(request);
|
|
2365
|
+
}
|
|
2366
|
+
const filename = (decoded.startsWith(assets) ? decoded.slice(assets.length) : decoded).slice(1);
|
|
2367
|
+
const filename_html = `${filename}/index.html`;
|
|
2368
|
+
const is_asset = manifest.assets.has(filename) || filename in manifest.server_assets;
|
|
2369
|
+
const is_asset_html = manifest.assets.has(filename_html) || filename_html in manifest.server_assets;
|
|
2370
|
+
if (is_asset || is_asset_html) {
|
|
2371
|
+
const file = is_asset ? filename : filename_html;
|
|
2372
|
+
if (state.read) {
|
|
2373
|
+
const type = is_asset ? manifest.mime_types[filename.slice(filename.lastIndexOf("."))] : "text/html";
|
|
2374
|
+
return new Response(state.read(file), { headers: type ? { "content-type": type } : {} });
|
|
2375
|
+
} else if (read_implementation && file in manifest.server_assets) {
|
|
2376
|
+
const length = manifest.server_assets[file];
|
|
2377
|
+
const type = manifest.mime_types[file.slice(file.lastIndexOf("."))];
|
|
2378
|
+
return new Response(read_implementation(file), { headers: {
|
|
2379
|
+
"Content-Length": "" + length,
|
|
2380
|
+
"Content-Type": type
|
|
2381
|
+
} });
|
|
2382
|
+
}
|
|
2383
|
+
return await fetch(request, { redirect: "manual" });
|
|
2384
|
+
}
|
|
2385
|
+
if (has_prerendered_path(decoded)) return await fetch(request, { redirect: "manual" });
|
|
2386
|
+
if (credentials !== "omit") {
|
|
2387
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
2388
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
2389
|
+
const authorization = event.request.headers.get("authorization");
|
|
2390
|
+
if (authorization && !request.headers.has("authorization")) request.headers.set("authorization", authorization);
|
|
2391
|
+
}
|
|
2392
|
+
if (!request.headers.has("accept")) request.headers.set("accept", "*/*");
|
|
2393
|
+
const accept_language = event.request.headers.get("accept-language");
|
|
2394
|
+
if (accept_language && !request.headers.has("accept-language")) request.headers.set("accept-language", accept_language);
|
|
2395
|
+
const response = await internal_fetch(request, state);
|
|
2396
|
+
for (const str of response.headers.getSetCookie()) {
|
|
2397
|
+
const { name, value, ...cookie_options } = parseSetCookie(str, { decode: (v) => v });
|
|
2398
|
+
set_internal(name, value, {
|
|
2399
|
+
path: cookie_options.path ?? (url.pathname.split("/").slice(0, -1).join("/") || "/"),
|
|
2400
|
+
encode: (value2) => value2,
|
|
2401
|
+
...cookie_options
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
return response;
|
|
2405
|
+
}
|
|
2406
|
+
});
|
|
2407
|
+
};
|
|
2408
|
+
return (input, init2) => {
|
|
2409
|
+
const response = server_fetch(input, init2);
|
|
2410
|
+
response.catch(noop);
|
|
2411
|
+
return response;
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
function normalize_fetch_input(info, init2, url) {
|
|
2415
|
+
if (info instanceof Request) return info;
|
|
2416
|
+
return new Request(typeof info === "string" ? new URL(info, url) : info, init2);
|
|
2417
|
+
}
|
|
2418
|
+
async function internal_fetch(request, state) {
|
|
2419
|
+
if (request.signal?.aborted) throw new DOMException("The operation was aborted.", "AbortError");
|
|
2420
|
+
const subrequest_state = fork_state_for_subrequest(state);
|
|
2421
|
+
if (!request.signal) return await respond$1(request, subrequest_state);
|
|
2422
|
+
let remove_abort_listener = noop;
|
|
2423
|
+
const abort_promise = new Promise((_, reject) => {
|
|
2424
|
+
const on_abort = () => {
|
|
2425
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
2426
|
+
};
|
|
2427
|
+
request.signal.addEventListener("abort", on_abort, { once: true });
|
|
2428
|
+
remove_abort_listener = () => request.signal.removeEventListener("abort", on_abort);
|
|
2429
|
+
});
|
|
2430
|
+
return Promise.race([respond$1(request, subrequest_state), abort_promise]).finally(remove_abort_listener);
|
|
2431
|
+
}
|
|
2432
|
+
var payload;
|
|
2433
|
+
var etag;
|
|
2434
|
+
var headers;
|
|
2435
|
+
function get_public_env(request) {
|
|
2436
|
+
payload ??= uneval(rendered_env);
|
|
2437
|
+
etag ??= `W/${Date.now()}`;
|
|
2438
|
+
headers ??= new Headers({
|
|
2439
|
+
"content-type": "application/javascript; charset=utf-8",
|
|
2440
|
+
etag
|
|
2441
|
+
});
|
|
2442
|
+
if (request.headers.get("if-none-match") === etag) return new Response(void 0, {
|
|
2443
|
+
status: 304,
|
|
2444
|
+
headers
|
|
2445
|
+
});
|
|
2446
|
+
return new Response(`export const env=${payload}`, { headers });
|
|
2447
|
+
}
|
|
2448
|
+
var default_transform = ({ html }) => html;
|
|
2449
|
+
var default_filter = () => false;
|
|
2450
|
+
var default_preload = ({ type }) => type === "js" || type === "css";
|
|
2451
|
+
var non_html_fetch_destinations = /* @__PURE__ */ new Set([
|
|
2452
|
+
"audio",
|
|
2453
|
+
"audioworklet",
|
|
2454
|
+
"font",
|
|
2455
|
+
"image",
|
|
2456
|
+
"json",
|
|
2457
|
+
"manifest",
|
|
2458
|
+
"paintworklet",
|
|
2459
|
+
"report",
|
|
2460
|
+
"script",
|
|
2461
|
+
"serviceworker",
|
|
2462
|
+
"sharedworker",
|
|
2463
|
+
"style",
|
|
2464
|
+
"track",
|
|
2465
|
+
"video",
|
|
2466
|
+
"webidentity",
|
|
2467
|
+
"worker",
|
|
2468
|
+
"xslt"
|
|
2469
|
+
]);
|
|
2470
|
+
var page_methods = /* @__PURE__ */ new Set([
|
|
2471
|
+
"GET",
|
|
2472
|
+
"HEAD",
|
|
2473
|
+
"POST"
|
|
2474
|
+
]);
|
|
2475
|
+
var allowed_page_methods = /* @__PURE__ */ new Set([
|
|
2476
|
+
"GET",
|
|
2477
|
+
"HEAD",
|
|
2478
|
+
"OPTIONS"
|
|
2479
|
+
]);
|
|
2480
|
+
var respond$1 = propagate_context(internal_respond);
|
|
2481
|
+
async function internal_respond(request, state) {
|
|
2482
|
+
const url = new URL(request.url);
|
|
2483
|
+
const is_route_resolution_request = has_resolution_suffix(url.pathname);
|
|
2484
|
+
const is_data_request = has_data_suffix(url.pathname);
|
|
2485
|
+
const remote_id = get_remote_id(url);
|
|
2486
|
+
{
|
|
2487
|
+
const request_origin = request.headers.get("origin");
|
|
2488
|
+
const self_origin = get_self_origin(void 0, url.origin);
|
|
2489
|
+
if (remote_id) {
|
|
2490
|
+
if (is_remote_forbidden({
|
|
2491
|
+
request,
|
|
2492
|
+
request_origin,
|
|
2493
|
+
self_origin
|
|
2494
|
+
})) return Response.json({ message: "Cross-site remote requests are forbidden" }, { status: 403 });
|
|
2495
|
+
} else if (is_csrf_forbidden({
|
|
2496
|
+
request,
|
|
2497
|
+
request_origin,
|
|
2498
|
+
self_origin,
|
|
2499
|
+
trusted_origins: options.csrf_trusted_origins
|
|
2500
|
+
})) {
|
|
2501
|
+
const message = `Cross-site ${request.method} form submissions are forbidden`;
|
|
2502
|
+
const opts = { status: 403 };
|
|
2503
|
+
if (request.headers.get("accept") === "application/json") return Response.json({ message }, opts);
|
|
2504
|
+
return text(message, opts);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
let invalidated_data_nodes;
|
|
2508
|
+
let skip_route_resolution = false;
|
|
2509
|
+
let is_route_id_resolution_request = false;
|
|
2510
|
+
if (is_route_resolution_request) {
|
|
2511
|
+
url.pathname = strip_resolution_suffix(url.pathname);
|
|
2512
|
+
is_route_id_resolution_request = is_route_id_resolution_path(url.pathname);
|
|
2513
|
+
} else if (is_data_request) {
|
|
2514
|
+
url.pathname = strip_data_suffix(url.pathname) + (url.searchParams.get("x-sveltekit-trailing-slash") === "1" ? "/" : "") || "/";
|
|
2515
|
+
url.searchParams.delete(TRAILING_SLASH_PARAM);
|
|
2516
|
+
invalidated_data_nodes = url.searchParams.get(INVALIDATED_PARAM)?.split("").map((node) => node === "1");
|
|
2517
|
+
url.searchParams.delete(INVALIDATED_PARAM);
|
|
2518
|
+
} else if (remote_id) {
|
|
2519
|
+
const pathname = request.headers.get("x-sveltekit-pathname");
|
|
2520
|
+
if (pathname === null) skip_route_resolution = true;
|
|
2521
|
+
else {
|
|
2522
|
+
url.pathname = pathname;
|
|
2523
|
+
url.search = request.headers.get("x-sveltekit-search") ?? "";
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
for (const key of url.searchParams.keys()) if (key.startsWith("x-sveltekit-")) return text(`Cannot use reserved query parameter "${key}"`, { status: 400 });
|
|
2527
|
+
const headers2 = {};
|
|
2528
|
+
const { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash } = get_cookies(request, url);
|
|
2529
|
+
const event = {
|
|
2530
|
+
cookies,
|
|
2531
|
+
fetch: null,
|
|
2532
|
+
getClientAddress: state.getClientAddress || (() => {
|
|
2533
|
+
client_address_unsupported({ adapter: "@sveltejs/adapter-node" });
|
|
2534
|
+
}),
|
|
2535
|
+
locals: {},
|
|
2536
|
+
params: {},
|
|
2537
|
+
platform: state.emulator?.platform ? await state.emulator.platform({
|
|
2538
|
+
config: {},
|
|
2539
|
+
prerender: !!state.prerendering?.fallback
|
|
2540
|
+
}) : state.platform,
|
|
2541
|
+
request,
|
|
2542
|
+
route: { id: null },
|
|
2543
|
+
setHeaders: (new_headers) => {
|
|
2544
|
+
for (const key in new_headers) {
|
|
2545
|
+
const lower = key.toLowerCase();
|
|
2546
|
+
const value = new_headers[key];
|
|
2547
|
+
if (lower === "set-cookie") set_headers_cookie();
|
|
2548
|
+
else if (lower in headers2) {
|
|
2549
|
+
if (lower === "server-timing") headers2[lower] += ", " + value;
|
|
2550
|
+
else header_already_set({ name: key });
|
|
2551
|
+
} else {
|
|
2552
|
+
headers2[lower] = value;
|
|
2553
|
+
if (state.prerendering && lower === "cache-control") state.prerendering.cache = value;
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
},
|
|
2557
|
+
url,
|
|
2558
|
+
isDataRequest: is_data_request,
|
|
2559
|
+
isSubRequest: state.depth > 0,
|
|
2560
|
+
isRemoteRequest: !!remote_id
|
|
2561
|
+
};
|
|
2562
|
+
event.fetch = create_fetch({
|
|
2563
|
+
event,
|
|
2564
|
+
state,
|
|
2565
|
+
get_cookie_header,
|
|
2566
|
+
set_internal
|
|
2567
|
+
});
|
|
2568
|
+
let resolved_path = url.pathname;
|
|
2569
|
+
if (!remote_id && !is_route_id_resolution_request) {
|
|
2570
|
+
const prerendering_reroute_state = state.prerendering?.inside_reroute;
|
|
2571
|
+
try {
|
|
2572
|
+
if (state.prerendering) state.prerendering.inside_reroute = true;
|
|
2573
|
+
resolved_path = await hooks.reroute({
|
|
2574
|
+
url: new URL(url),
|
|
2575
|
+
fetch: event.fetch
|
|
2576
|
+
}) ?? url.pathname;
|
|
2577
|
+
if (!manifest.routes.length && resolved_path !== url.pathname) state.rerouted_url = denormalise_url({
|
|
2578
|
+
request_url: request.url,
|
|
2579
|
+
resolved_path,
|
|
2580
|
+
is_data_request,
|
|
2581
|
+
is_route_resolution_request
|
|
2582
|
+
}).toString();
|
|
2583
|
+
} catch {
|
|
2584
|
+
return text("Internal Server Error", { status: 500 });
|
|
2585
|
+
} finally {
|
|
2586
|
+
if (state.prerendering) state.prerendering.inside_reroute = prerendering_reroute_state;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
let resolve_opts = {
|
|
2590
|
+
transformPageChunk: default_transform,
|
|
2591
|
+
filterSerializedResponseHeaders: default_filter,
|
|
2592
|
+
preload: default_preload
|
|
2593
|
+
};
|
|
2594
|
+
let trailing_slash = "never";
|
|
2595
|
+
let page_nodes;
|
|
2596
|
+
let decoded_pathname;
|
|
2597
|
+
try {
|
|
2598
|
+
resolved_path = decode_pathname(resolved_path);
|
|
2599
|
+
decoded_pathname = decode_pathname(url.pathname);
|
|
2600
|
+
} catch {
|
|
2601
|
+
resolved_path = null;
|
|
2602
|
+
return await handle();
|
|
2603
|
+
}
|
|
2604
|
+
if (resolved_path !== decoded_pathname && !state.prerendering?.fallback && has_prerendered_path(resolved_path)) {
|
|
2605
|
+
const url2 = denormalise_url({
|
|
2606
|
+
request_url: request.url,
|
|
2607
|
+
resolved_path,
|
|
2608
|
+
is_data_request,
|
|
2609
|
+
is_route_resolution_request
|
|
2610
|
+
});
|
|
2611
|
+
try {
|
|
2612
|
+
const response = await fetch(new Request(url2, request), { redirect: "manual" });
|
|
2613
|
+
const headers3 = new Headers(response.headers);
|
|
2614
|
+
if (headers3.has("content-encoding")) {
|
|
2615
|
+
headers3.delete("content-encoding");
|
|
2616
|
+
headers3.delete("content-length");
|
|
2617
|
+
}
|
|
2618
|
+
return new Response(response.body, {
|
|
2619
|
+
headers: headers3,
|
|
2620
|
+
status: response.status,
|
|
2621
|
+
statusText: response.statusText
|
|
2622
|
+
});
|
|
2623
|
+
} catch (error) {
|
|
2624
|
+
return await handle_fatal_error(event, state, error);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
let route = null;
|
|
2628
|
+
if (is_route_resolution_request) {
|
|
2629
|
+
if (is_route_id_resolution_request) return resolve_route_by_id(extract_route_id(resolved_path), new URL(request.url));
|
|
2630
|
+
return resolve_route(resolved_path, new URL(request.url));
|
|
2631
|
+
}
|
|
2632
|
+
if (resolved_path === `/_app/env.js`) return get_public_env(request);
|
|
2633
|
+
if (!remote_id && resolved_path.startsWith(`/_app`)) {
|
|
2634
|
+
const headers3 = new Headers();
|
|
2635
|
+
headers3.set("cache-control", "public, max-age=0, must-revalidate");
|
|
2636
|
+
return text("Not found", {
|
|
2637
|
+
status: 404,
|
|
2638
|
+
headers: headers3
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
if (!state.prerendering?.fallback && !skip_route_resolution) try {
|
|
2642
|
+
const matchers = await manifest.matchers();
|
|
2643
|
+
const result = find_route(resolved_path, manifest.routes, matchers);
|
|
2644
|
+
if (result) {
|
|
2645
|
+
route = result.route;
|
|
2646
|
+
event.route = { id: route.id };
|
|
2647
|
+
event.params = result.params;
|
|
2648
|
+
}
|
|
2649
|
+
} catch (e) {
|
|
2650
|
+
return await handle_fatal_error(event, state, e);
|
|
2651
|
+
}
|
|
2652
|
+
try {
|
|
2653
|
+
page_nodes = route?.page ? new PageNodes(await load_page_nodes(route.page)) : void 0;
|
|
2654
|
+
if (route && !remote_id) {
|
|
2655
|
+
if (url.pathname === "" || url.pathname === "/") trailing_slash = "always";
|
|
2656
|
+
else if (page_nodes) trailing_slash = page_nodes.trailing_slash();
|
|
2657
|
+
else if (route.endpoint) trailing_slash = (await route.endpoint()).trailingSlash ?? "never";
|
|
2658
|
+
if (!is_data_request) {
|
|
2659
|
+
const normalized = normalize_path(url.pathname, trailing_slash);
|
|
2660
|
+
if (normalized !== url.pathname && !state.prerendering?.fallback) return new Response(void 0, {
|
|
2661
|
+
status: 308,
|
|
2662
|
+
headers: {
|
|
2663
|
+
"x-sveltekit-normalize": "1",
|
|
2664
|
+
location: relative_pathname(url.pathname, normalized) + (url.search === "?" ? "" : url.search)
|
|
2665
|
+
}
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
if (state.before_handle || state.emulator?.platform) {
|
|
2669
|
+
let config = {};
|
|
2670
|
+
let prerender = false;
|
|
2671
|
+
if (route.endpoint) {
|
|
2672
|
+
const node = await route.endpoint();
|
|
2673
|
+
config = node.config ?? config;
|
|
2674
|
+
prerender = node.prerender ?? prerender;
|
|
2675
|
+
} else if (page_nodes) {
|
|
2676
|
+
config = page_nodes.get_config() ?? config;
|
|
2677
|
+
prerender = state.prerender_default = page_nodes.prerender();
|
|
2678
|
+
}
|
|
2679
|
+
if (state.emulator?.platform) event.platform = await state.emulator.platform({
|
|
2680
|
+
config,
|
|
2681
|
+
prerender
|
|
2682
|
+
});
|
|
2683
|
+
if (state.before_handle) return await state.before_handle(event, config, prerender, handle);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
return await handle();
|
|
2687
|
+
} catch (e) {
|
|
2688
|
+
if (e instanceof Redirect) try {
|
|
2689
|
+
const response = is_data_request || remote_id ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
|
|
2690
|
+
add_cookies_to_headers(response.headers, new_cookies.values());
|
|
2691
|
+
return response;
|
|
2692
|
+
} catch (err) {
|
|
2693
|
+
return await handle_fatal_error(event, state, err);
|
|
2694
|
+
}
|
|
2695
|
+
return await handle_fatal_error(event, state, e);
|
|
2696
|
+
}
|
|
2697
|
+
async function handle() {
|
|
2698
|
+
set_trailing_slash(trailing_slash);
|
|
2699
|
+
if (state.prerendering && !state.prerendering.fallback && !state.prerendering.inside_reroute) disable_search(url);
|
|
2700
|
+
const response = await record_span({
|
|
2701
|
+
name: "sveltekit.handle.root",
|
|
2702
|
+
attributes: {
|
|
2703
|
+
"http.route": event.route.id || "unknown",
|
|
2704
|
+
"http.method": event.request.method,
|
|
2705
|
+
"http.url": event.url.href,
|
|
2706
|
+
"sveltekit.is_data_request": is_data_request,
|
|
2707
|
+
"sveltekit.is_sub_request": event.isSubRequest
|
|
2708
|
+
},
|
|
2709
|
+
fn: async (root_span) => {
|
|
2710
|
+
const traced_event = {
|
|
2711
|
+
...event,
|
|
2712
|
+
tracing: {
|
|
2713
|
+
enabled: false,
|
|
2714
|
+
root: root_span,
|
|
2715
|
+
current: root_span
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
return await with_request_store({
|
|
2719
|
+
event: traced_event,
|
|
2720
|
+
state
|
|
2721
|
+
}, () => hooks.handle({
|
|
2722
|
+
event: traced_event,
|
|
2723
|
+
resolve: (event2, opts) => {
|
|
2724
|
+
return record_span({
|
|
2725
|
+
name: "sveltekit.resolve",
|
|
2726
|
+
attributes: { "http.route": event2.route.id || "unknown" },
|
|
2727
|
+
fn: (resolve_span) => {
|
|
2728
|
+
return with_request_store(null, () => resolve2(merge_tracing(event2, resolve_span), page_nodes, opts).then((response2) => {
|
|
2729
|
+
for (const key in headers2) {
|
|
2730
|
+
const value = headers2[key];
|
|
2731
|
+
response2.headers.set(key, value);
|
|
2732
|
+
}
|
|
2733
|
+
add_cookies_to_headers(response2.headers, new_cookies.values());
|
|
2734
|
+
if (state.prerendering && event2.route.id !== null) response2.headers.set("x-sveltekit-routeid", encodeURI(event2.route.id));
|
|
2735
|
+
resolve_span.setAttributes({
|
|
2736
|
+
"http.response.status_code": response2.status,
|
|
2737
|
+
"http.response.body.size": response2.headers.get("content-length") || "unknown"
|
|
2738
|
+
});
|
|
2739
|
+
return response2;
|
|
2740
|
+
}));
|
|
2741
|
+
}
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
}));
|
|
2745
|
+
}
|
|
2746
|
+
});
|
|
2747
|
+
if (response.status === 200 && response.headers.has("etag")) {
|
|
2748
|
+
let if_none_match_value = request.headers.get("if-none-match");
|
|
2749
|
+
if (if_none_match_value?.startsWith('W/"')) if_none_match_value = if_none_match_value.substring(2);
|
|
2750
|
+
const etag2 = response.headers.get("etag");
|
|
2751
|
+
if (if_none_match_value === etag2) {
|
|
2752
|
+
const headers3 = new Headers({ etag: etag2 });
|
|
2753
|
+
for (const key of [
|
|
2754
|
+
"cache-control",
|
|
2755
|
+
"content-location",
|
|
2756
|
+
"date",
|
|
2757
|
+
"expires",
|
|
2758
|
+
"vary"
|
|
2759
|
+
]) {
|
|
2760
|
+
const value = response.headers.get(key);
|
|
2761
|
+
if (value) headers3.set(key, value);
|
|
2762
|
+
}
|
|
2763
|
+
for (const cookie of response.headers.getSetCookie()) headers3.append("set-cookie", cookie);
|
|
2764
|
+
return new Response(void 0, {
|
|
2765
|
+
status: 304,
|
|
2766
|
+
headers: headers3
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
if (is_data_request && response.status >= 300 && response.status <= 308) {
|
|
2771
|
+
const location = response.headers.get("location");
|
|
2772
|
+
if (location) return redirect_json_response(new Redirect(response.status, location));
|
|
2773
|
+
}
|
|
2774
|
+
return response;
|
|
2775
|
+
}
|
|
2776
|
+
async function resolve2(event2, page_nodes2, opts) {
|
|
2777
|
+
try {
|
|
2778
|
+
if (opts) resolve_opts = {
|
|
2779
|
+
transformPageChunk: opts.transformPageChunk || default_transform,
|
|
2780
|
+
filterSerializedResponseHeaders: opts.filterSerializedResponseHeaders || default_filter,
|
|
2781
|
+
preload: opts.preload || default_preload
|
|
2782
|
+
};
|
|
2783
|
+
if (resolved_path === null) return await respond_with_error({
|
|
2784
|
+
event: event2,
|
|
2785
|
+
state,
|
|
2786
|
+
error: new SvelteKitError(400, "Malformed URI", `Failed to decode URI: ${event2.url.pathname}`),
|
|
2787
|
+
resolve_opts
|
|
2788
|
+
});
|
|
2789
|
+
if (state.prerendering?.fallback) return await render_response({
|
|
2790
|
+
event: event2,
|
|
2791
|
+
state,
|
|
2792
|
+
page_config: {
|
|
2793
|
+
ssr: false,
|
|
2794
|
+
csr: true
|
|
2795
|
+
},
|
|
2796
|
+
status: 200,
|
|
2797
|
+
error: null,
|
|
2798
|
+
branch: [{
|
|
2799
|
+
node: await manifest.nodes[0](),
|
|
2800
|
+
data: null,
|
|
2801
|
+
server_data: null
|
|
2802
|
+
}],
|
|
2803
|
+
fetched: [],
|
|
2804
|
+
resolve_opts,
|
|
2805
|
+
data_serializer: server_data_serializer(event2, state)
|
|
2806
|
+
});
|
|
2807
|
+
if (remote_id) return await handle_remote_call(event2, state, remote_id);
|
|
2808
|
+
if (route) {
|
|
2809
|
+
const method = event2.request.method;
|
|
2810
|
+
let response2;
|
|
2811
|
+
if (is_data_request) response2 = await render_data(event2, state, route, invalidated_data_nodes, trailing_slash);
|
|
2812
|
+
else {
|
|
2813
|
+
let endpoint;
|
|
2814
|
+
if (route.endpoint && (!route.page || !state.prerendering && is_endpoint_request(event2))) {
|
|
2815
|
+
endpoint = await route.endpoint();
|
|
2816
|
+
if (route.page && (method === "GET" || method === "HEAD" || method === "POST")) {
|
|
2817
|
+
if (!(method === "POST" ? !!(endpoint.POST || endpoint.fallback) : !!(endpoint.GET || endpoint.fallback || method === "HEAD" && endpoint.HEAD))) endpoint = void 0;
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
if (endpoint) response2 = await render_endpoint(event2, state, endpoint);
|
|
2821
|
+
else if (route.page) {
|
|
2822
|
+
if (!page_nodes2) throw new Error("page_nodes not found. This should never happen");
|
|
2823
|
+
else if (page_methods.has(method)) response2 = await render_page(event2, state, route.page, page_nodes2, resolve_opts);
|
|
2824
|
+
else {
|
|
2825
|
+
const allowed_methods = new Set(allowed_page_methods);
|
|
2826
|
+
if ((await manifest.nodes[route.page.leaf]())?.server?.actions) allowed_methods.add("POST");
|
|
2827
|
+
if (method === "OPTIONS") response2 = new Response(null, {
|
|
2828
|
+
status: 204,
|
|
2829
|
+
headers: { allow: Array.from(allowed_methods.values()).join(", ") }
|
|
2830
|
+
});
|
|
2831
|
+
else {
|
|
2832
|
+
const mod = [...allowed_methods].reduce((acc, curr) => {
|
|
2833
|
+
acc[curr] = true;
|
|
2834
|
+
return acc;
|
|
2835
|
+
}, {});
|
|
2836
|
+
response2 = method_not_allowed(mod, method);
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
} else throw new Error("Route is neither page nor endpoint. This should never happen");
|
|
2840
|
+
}
|
|
2841
|
+
if ((request.method === "GET" || request.method === "HEAD") && route.page && route.endpoint) {
|
|
2842
|
+
const vary = response2.headers.get("vary")?.split(",")?.map((v) => v.trim().toLowerCase());
|
|
2843
|
+
if (!(vary?.includes("accept") || vary?.includes("*"))) {
|
|
2844
|
+
response2 = new Response(response2.body, {
|
|
2845
|
+
status: response2.status,
|
|
2846
|
+
statusText: response2.statusText,
|
|
2847
|
+
headers: new Headers(response2.headers)
|
|
2848
|
+
});
|
|
2849
|
+
response2.headers.append("Vary", "Accept");
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
return response2;
|
|
2853
|
+
}
|
|
2854
|
+
if (state.error && event2.isSubRequest) {
|
|
2855
|
+
const headers3 = new Headers(request.headers);
|
|
2856
|
+
headers3.set("x-sveltekit-error", "true");
|
|
2857
|
+
return await fetch(request, {
|
|
2858
|
+
headers: headers3,
|
|
2859
|
+
redirect: "manual"
|
|
2860
|
+
});
|
|
2861
|
+
}
|
|
2862
|
+
if (state.error) return text("Internal Server Error", { status: 500 });
|
|
2863
|
+
if (state.depth === 0) {
|
|
2864
|
+
if (!state.prerendering && is_data_request && invalidated_data_nodes?.length === 1 && invalidated_data_nodes[0]) return await render_data(event2, state, { page: {
|
|
2865
|
+
layouts: [],
|
|
2866
|
+
leaf: 0
|
|
2867
|
+
} }, invalidated_data_nodes, "ignore");
|
|
2868
|
+
if (non_html_fetch_destinations.has(event2.request.headers.get("sec-fetch-dest") ?? "")) return text("Not Found", {
|
|
2869
|
+
status: 404,
|
|
2870
|
+
headers: { vary: "Sec-Fetch-Dest" }
|
|
2871
|
+
});
|
|
2872
|
+
return await respond_with_error({
|
|
2873
|
+
event: event2,
|
|
2874
|
+
state,
|
|
2875
|
+
error: new SvelteKitError(404, "Not Found", `Not found: ${event2.url.pathname}`),
|
|
2876
|
+
resolve_opts
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
if (state.prerendering) return text("not found", { status: 404 });
|
|
2880
|
+
const response = await fetch(request, { redirect: "manual" });
|
|
2881
|
+
return new Response(response.body, response);
|
|
2882
|
+
} catch (e) {
|
|
2883
|
+
return await handle_fatal_error(event2, state, e);
|
|
2884
|
+
} finally {
|
|
2885
|
+
event2.cookies.set = () => {
|
|
2886
|
+
cookies_set_after_response();
|
|
2887
|
+
};
|
|
2888
|
+
event2.setHeaders = () => {
|
|
2889
|
+
set_headers_after_response();
|
|
2890
|
+
};
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
function load_page_nodes(page) {
|
|
2895
|
+
return Promise.all([...page.layouts.map((n) => n == void 0 ? n : manifest.nodes[n]()), manifest.nodes[page.leaf]()]);
|
|
2896
|
+
}
|
|
2897
|
+
function propagate_context(fn) {
|
|
2898
|
+
return async (req, ...rest) => {
|
|
2899
|
+
if (otel === null) return fn(req, ...rest);
|
|
2900
|
+
const { propagation, context } = await otel;
|
|
2901
|
+
const c = propagation.extract(context.active(), Object.fromEntries(req.headers));
|
|
2902
|
+
return context.with(c, async () => {
|
|
2903
|
+
return await fn(req, ...rest);
|
|
2904
|
+
});
|
|
2905
|
+
};
|
|
2906
|
+
}
|
|
2907
|
+
function denormalise_url({ request_url, resolved_path, is_data_request, is_route_resolution_request }) {
|
|
2908
|
+
const url = new URL(request_url);
|
|
2909
|
+
url.pathname = is_data_request ? add_data_suffix(resolved_path) : is_route_resolution_request ? add_resolution_suffix(resolved_path) : resolved_path;
|
|
2910
|
+
return url;
|
|
2911
|
+
}
|
|
2912
|
+
var init_promise;
|
|
2913
|
+
async function init() {
|
|
2914
|
+
await (init_promise ??= (async () => {
|
|
2915
|
+
try {
|
|
2916
|
+
const module = await get_hooks();
|
|
2917
|
+
set_hooks({
|
|
2918
|
+
handle: module.handle || (({ event, resolve: resolve2 }) => resolve2(event)),
|
|
2919
|
+
handleError: module.handleError || (({ kind, error, issues }) => {
|
|
2920
|
+
if (kind === "validation") {
|
|
2921
|
+
console.error("Remote function schema validation failed:", issues);
|
|
2922
|
+
return;
|
|
2923
|
+
}
|
|
2924
|
+
if (kind !== "unknown") return;
|
|
2925
|
+
let e = error;
|
|
2926
|
+
while (e instanceof Error) {
|
|
2927
|
+
if (e.stack) console.error(e.stack);
|
|
2928
|
+
e = e.cause;
|
|
2929
|
+
}
|
|
2930
|
+
if (e) console.error(String(e));
|
|
2931
|
+
}),
|
|
2932
|
+
handleFetch: module.handleFetch || (({ request, fetch: fetch2 }) => fetch2(request)),
|
|
2933
|
+
reroute: module.reroute || noop
|
|
2934
|
+
});
|
|
2935
|
+
init_transport(module.transport ?? {});
|
|
2936
|
+
if (module.init) await module.init();
|
|
2937
|
+
} catch (e) {
|
|
2938
|
+
throw e;
|
|
2939
|
+
}
|
|
2940
|
+
})());
|
|
2941
|
+
}
|
|
2942
|
+
async function respond_to(request, options2) {
|
|
2943
|
+
const request_state = create_request_state(options2);
|
|
2944
|
+
const response = await respond$1(request, request_state);
|
|
2945
|
+
if (request_state.rerouted_url) response.headers.set(REROUTED_URL_HEADER, request_state.rerouted_url);
|
|
2946
|
+
if (request.method === "HEAD" && response.body !== null) {
|
|
2947
|
+
response.body.cancel().catch(noop);
|
|
2948
|
+
return new Response(null, response);
|
|
2949
|
+
}
|
|
2950
|
+
return response;
|
|
2951
|
+
}
|
|
2952
|
+
function serialise(fn) {
|
|
2953
|
+
let current = null;
|
|
2954
|
+
return async (...args) => {
|
|
2955
|
+
const { promise, resolve: resolve2 } = Promise.withResolvers();
|
|
2956
|
+
const previous = current;
|
|
2957
|
+
current = promise;
|
|
2958
|
+
await previous;
|
|
2959
|
+
return fn(...args).finally(resolve2);
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
var respond = IN_WEBCONTAINER ? serialise(respond_to) : respond_to;
|
|
2963
|
+
export {
|
|
2964
|
+
init,
|
|
2965
|
+
respond,
|
|
2966
|
+
set_env
|
|
2967
|
+
};
|