@qwik.dev/router 2.0.0-beta.13 → 2.0.0-beta.15
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/lib/adapters/azure-swa/vite/index.mjs +7 -7
- package/lib/adapters/bun-server/vite/index.mjs +7 -7
- package/lib/adapters/cloud-run/vite/index.mjs +7 -7
- package/lib/adapters/cloudflare-pages/vite/index.mjs +8 -8
- package/lib/adapters/deno-server/vite/index.mjs +7 -7
- package/lib/adapters/netlify-edge/vite/index.mjs +7 -7
- package/lib/adapters/node-server/vite/index.mjs +7 -7
- package/lib/adapters/shared/vite/index.mjs +8 -8
- package/lib/adapters/ssg/vite/index.mjs +7 -8
- package/lib/adapters/vercel-edge/vite/index.mjs +7 -7
- package/lib/chunks/error-handler.mjs +2 -4
- package/lib/chunks/format-error.mjs +6 -6
- package/lib/chunks/fs.mjs +6 -27
- package/lib/chunks/index.mjs +39 -31
- package/lib/chunks/mime-types.mjs +2 -3
- package/lib/chunks/routing.qwik.mjs +23 -47
- package/lib/chunks/types.qwik.mjs +2 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.qwik.mjs +48 -68
- package/lib/middleware/aws-lambda/index.mjs +4 -5
- package/lib/middleware/azure-swa/index.mjs +6 -7
- package/lib/middleware/bun/index.mjs +8 -9
- package/lib/middleware/cloudflare-pages/index.mjs +5 -6
- package/lib/middleware/deno/index.mjs +7 -8
- package/lib/middleware/firebase/index.mjs +4 -5
- package/lib/middleware/netlify-edge/index.mjs +5 -6
- package/lib/middleware/node/index.mjs +15 -11
- package/lib/middleware/request-handler/index.d.ts +2 -2
- package/lib/middleware/request-handler/index.mjs +64 -79
- package/lib/middleware/vercel-edge/index.mjs +5 -6
- package/lib/service-worker/index.mjs +2 -3
- package/lib/ssg/index.mjs +3 -4
- package/lib/vite/index.d.ts +7 -1
- package/lib/vite/index.mjs +91 -68
- package/package.json +21 -39
- package/lib/adapters/azure-swa/vite/index.cjs +0 -61
- package/lib/adapters/bun-server/vite/index.cjs +0 -27
- package/lib/adapters/cloud-run/vite/index.cjs +0 -24
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -65
- package/lib/adapters/deno-server/vite/index.cjs +0 -39
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -88
- package/lib/adapters/node-server/vite/index.cjs +0 -27
- package/lib/adapters/shared/vite/index.cjs +0 -306
- package/lib/adapters/ssg/vite/index.cjs +0 -19
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -81
- package/lib/chunks/error-handler.cjs +0 -58
- package/lib/chunks/format-error.cjs +0 -136
- package/lib/chunks/fs.cjs +0 -274
- package/lib/chunks/index.cjs +0 -877
- package/lib/chunks/mime-types.cjs +0 -52
- package/lib/chunks/routing.qwik.cjs +0 -452
- package/lib/chunks/types.qwik.cjs +0 -24
- package/lib/index.qwik.cjs +0 -1662
- package/lib/middleware/aws-lambda/index.cjs +0 -52
- package/lib/middleware/azure-swa/index.cjs +0 -92
- package/lib/middleware/bun/index.cjs +0 -143
- package/lib/middleware/cloudflare-pages/index.cjs +0 -96
- package/lib/middleware/deno/index.cjs +0 -130
- package/lib/middleware/firebase/index.cjs +0 -33
- package/lib/middleware/netlify-edge/index.cjs +0 -71
- package/lib/middleware/node/index.cjs +0 -219
- package/lib/middleware/request-handler/index.cjs +0 -1488
- package/lib/middleware/vercel-edge/index.cjs +0 -98
- package/lib/service-worker/index.cjs +0 -5
- package/lib/ssg/index.cjs +0 -15
- package/lib/vite/index.cjs +0 -2021
|
@@ -1,1488 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __typeError = (msg) => {
|
|
9
|
-
throw TypeError(msg);
|
|
10
|
-
};
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
30
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
31
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
32
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
33
|
-
var _a, _b, _c, _pendingHighSurrogate, _handle, _transform;
|
|
34
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
35
|
-
const build = require("@qwik.dev/core/build");
|
|
36
|
-
const routing = require("../../chunks/routing.qwik.cjs");
|
|
37
|
-
const core = require("@qwik.dev/core");
|
|
38
|
-
const internal = require("@qwik.dev/core/internal");
|
|
39
|
-
const types = require("../../chunks/types.qwik.cjs");
|
|
40
|
-
const requestHandler$1 = require("@qwik.dev/router/middleware/request-handler");
|
|
41
|
-
const errorHandler = require("../../chunks/error-handler.cjs");
|
|
42
|
-
require("@qwik.dev/core/preloader");
|
|
43
|
-
var HttpStatus = /* @__PURE__ */ ((HttpStatus2) => {
|
|
44
|
-
HttpStatus2[HttpStatus2["Continue"] = 100] = "Continue";
|
|
45
|
-
HttpStatus2[HttpStatus2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
46
|
-
HttpStatus2[HttpStatus2["Processing"] = 102] = "Processing";
|
|
47
|
-
HttpStatus2[HttpStatus2["Ok"] = 200] = "Ok";
|
|
48
|
-
HttpStatus2[HttpStatus2["Created"] = 201] = "Created";
|
|
49
|
-
HttpStatus2[HttpStatus2["Accepted"] = 202] = "Accepted";
|
|
50
|
-
HttpStatus2[HttpStatus2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
51
|
-
HttpStatus2[HttpStatus2["NoContent"] = 204] = "NoContent";
|
|
52
|
-
HttpStatus2[HttpStatus2["ResetContent"] = 205] = "ResetContent";
|
|
53
|
-
HttpStatus2[HttpStatus2["PartialContent"] = 206] = "PartialContent";
|
|
54
|
-
HttpStatus2[HttpStatus2["MultiStatus"] = 207] = "MultiStatus";
|
|
55
|
-
HttpStatus2[HttpStatus2["AlreadyReported"] = 208] = "AlreadyReported";
|
|
56
|
-
HttpStatus2[HttpStatus2["ImUsed"] = 226] = "ImUsed";
|
|
57
|
-
HttpStatus2[HttpStatus2["MultipleChoices"] = 300] = "MultipleChoices";
|
|
58
|
-
HttpStatus2[HttpStatus2["MovedPermanently"] = 301] = "MovedPermanently";
|
|
59
|
-
HttpStatus2[HttpStatus2["Found"] = 302] = "Found";
|
|
60
|
-
HttpStatus2[HttpStatus2["SeeOther"] = 303] = "SeeOther";
|
|
61
|
-
HttpStatus2[HttpStatus2["NotModified"] = 304] = "NotModified";
|
|
62
|
-
HttpStatus2[HttpStatus2["UseProxy"] = 305] = "UseProxy";
|
|
63
|
-
HttpStatus2[HttpStatus2["SwitchProxy"] = 306] = "SwitchProxy";
|
|
64
|
-
HttpStatus2[HttpStatus2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
65
|
-
HttpStatus2[HttpStatus2["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
66
|
-
HttpStatus2[HttpStatus2["BadRequest"] = 400] = "BadRequest";
|
|
67
|
-
HttpStatus2[HttpStatus2["Unauthorized"] = 401] = "Unauthorized";
|
|
68
|
-
HttpStatus2[HttpStatus2["PaymentRequired"] = 402] = "PaymentRequired";
|
|
69
|
-
HttpStatus2[HttpStatus2["Forbidden"] = 403] = "Forbidden";
|
|
70
|
-
HttpStatus2[HttpStatus2["NotFound"] = 404] = "NotFound";
|
|
71
|
-
HttpStatus2[HttpStatus2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
72
|
-
HttpStatus2[HttpStatus2["NotAcceptable"] = 406] = "NotAcceptable";
|
|
73
|
-
HttpStatus2[HttpStatus2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
74
|
-
HttpStatus2[HttpStatus2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
75
|
-
HttpStatus2[HttpStatus2["Conflict"] = 409] = "Conflict";
|
|
76
|
-
HttpStatus2[HttpStatus2["Gone"] = 410] = "Gone";
|
|
77
|
-
HttpStatus2[HttpStatus2["LengthRequired"] = 411] = "LengthRequired";
|
|
78
|
-
HttpStatus2[HttpStatus2["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
79
|
-
HttpStatus2[HttpStatus2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
80
|
-
HttpStatus2[HttpStatus2["UriTooLong"] = 414] = "UriTooLong";
|
|
81
|
-
HttpStatus2[HttpStatus2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
82
|
-
HttpStatus2[HttpStatus2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
83
|
-
HttpStatus2[HttpStatus2["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
84
|
-
HttpStatus2[HttpStatus2["IAmATeapot"] = 418] = "IAmATeapot";
|
|
85
|
-
HttpStatus2[HttpStatus2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
86
|
-
HttpStatus2[HttpStatus2["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
87
|
-
HttpStatus2[HttpStatus2["Locked"] = 423] = "Locked";
|
|
88
|
-
HttpStatus2[HttpStatus2["FailedDependency"] = 424] = "FailedDependency";
|
|
89
|
-
HttpStatus2[HttpStatus2["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
90
|
-
HttpStatus2[HttpStatus2["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
91
|
-
HttpStatus2[HttpStatus2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
92
|
-
HttpStatus2[HttpStatus2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
93
|
-
HttpStatus2[HttpStatus2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
94
|
-
HttpStatus2[HttpStatus2["InternalServerError"] = 500] = "InternalServerError";
|
|
95
|
-
HttpStatus2[HttpStatus2["NotImplemented"] = 501] = "NotImplemented";
|
|
96
|
-
HttpStatus2[HttpStatus2["BadGateway"] = 502] = "BadGateway";
|
|
97
|
-
HttpStatus2[HttpStatus2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
98
|
-
HttpStatus2[HttpStatus2["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
99
|
-
HttpStatus2[HttpStatus2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
|
|
100
|
-
HttpStatus2[HttpStatus2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
101
|
-
HttpStatus2[HttpStatus2["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
102
|
-
HttpStatus2[HttpStatus2["LoopDetected"] = 508] = "LoopDetected";
|
|
103
|
-
HttpStatus2[HttpStatus2["NotExtended"] = 510] = "NotExtended";
|
|
104
|
-
HttpStatus2[HttpStatus2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
105
|
-
return HttpStatus2;
|
|
106
|
-
})(HttpStatus || {});
|
|
107
|
-
function createCacheControl(cacheControl) {
|
|
108
|
-
const controls = [];
|
|
109
|
-
if (cacheControl === "day") {
|
|
110
|
-
cacheControl = 60 * 60 * 24;
|
|
111
|
-
} else if (cacheControl === "week") {
|
|
112
|
-
cacheControl = 60 * 60 * 24 * 7;
|
|
113
|
-
} else if (cacheControl === "month") {
|
|
114
|
-
cacheControl = 60 * 60 * 24 * 30;
|
|
115
|
-
} else if (cacheControl === "year") {
|
|
116
|
-
cacheControl = 60 * 60 * 24 * 365;
|
|
117
|
-
} else if (cacheControl === "private") {
|
|
118
|
-
cacheControl = {
|
|
119
|
-
private: true,
|
|
120
|
-
noCache: true
|
|
121
|
-
};
|
|
122
|
-
} else if (cacheControl === "immutable") {
|
|
123
|
-
cacheControl = {
|
|
124
|
-
public: true,
|
|
125
|
-
immutable: true,
|
|
126
|
-
maxAge: 60 * 60 * 24 * 365
|
|
127
|
-
};
|
|
128
|
-
} else if (cacheControl === "no-cache") {
|
|
129
|
-
cacheControl = {
|
|
130
|
-
noCache: true
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (typeof cacheControl === "number") {
|
|
134
|
-
cacheControl = {
|
|
135
|
-
maxAge: cacheControl,
|
|
136
|
-
sMaxAge: cacheControl
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (cacheControl.immutable) {
|
|
140
|
-
controls.push("immutable");
|
|
141
|
-
}
|
|
142
|
-
if (cacheControl.maxAge) {
|
|
143
|
-
controls.push(`max-age=${cacheControl.maxAge}`);
|
|
144
|
-
}
|
|
145
|
-
if (cacheControl.sMaxAge) {
|
|
146
|
-
controls.push(`s-maxage=${cacheControl.sMaxAge}`);
|
|
147
|
-
}
|
|
148
|
-
if (cacheControl.noStore) {
|
|
149
|
-
controls.push("no-store");
|
|
150
|
-
}
|
|
151
|
-
if (cacheControl.noCache) {
|
|
152
|
-
controls.push("no-cache");
|
|
153
|
-
}
|
|
154
|
-
if (cacheControl.private) {
|
|
155
|
-
controls.push("private");
|
|
156
|
-
}
|
|
157
|
-
if (cacheControl.public) {
|
|
158
|
-
controls.push("public");
|
|
159
|
-
}
|
|
160
|
-
if (cacheControl.staleWhileRevalidate) {
|
|
161
|
-
controls.push(`stale-while-revalidate=${cacheControl.staleWhileRevalidate}`);
|
|
162
|
-
}
|
|
163
|
-
if (cacheControl.staleIfError) {
|
|
164
|
-
controls.push(`stale-if-error=${cacheControl.staleIfError}`);
|
|
165
|
-
}
|
|
166
|
-
return controls.join(", ");
|
|
167
|
-
}
|
|
168
|
-
const SAMESITE = {
|
|
169
|
-
lax: "Lax",
|
|
170
|
-
Lax: "Lax",
|
|
171
|
-
None: "None",
|
|
172
|
-
none: "None",
|
|
173
|
-
strict: "Strict",
|
|
174
|
-
Strict: "Strict"
|
|
175
|
-
};
|
|
176
|
-
const UNIT = {
|
|
177
|
-
seconds: 1,
|
|
178
|
-
minutes: 1 * 60,
|
|
179
|
-
hours: 1 * 60 * 60,
|
|
180
|
-
days: 1 * 60 * 60 * 24,
|
|
181
|
-
weeks: 1 * 60 * 60 * 24 * 7
|
|
182
|
-
};
|
|
183
|
-
const createSetCookieValue = (cookieName, cookieValue, options) => {
|
|
184
|
-
const c = [`${cookieName}=${cookieValue}`];
|
|
185
|
-
if (typeof options.domain === "string") {
|
|
186
|
-
c.push(`Domain=${options.domain}`);
|
|
187
|
-
}
|
|
188
|
-
if (typeof options.maxAge === "number") {
|
|
189
|
-
c.push(`Max-Age=${options.maxAge}`);
|
|
190
|
-
} else if (Array.isArray(options.maxAge)) {
|
|
191
|
-
c.push(`Max-Age=${options.maxAge[0] * UNIT[options.maxAge[1]]}`);
|
|
192
|
-
} else if (typeof options.expires === "number" || typeof options.expires == "string") {
|
|
193
|
-
c.push(`Expires=${options.expires}`);
|
|
194
|
-
} else if (options.expires instanceof Date) {
|
|
195
|
-
c.push(`Expires=${options.expires.toUTCString()}`);
|
|
196
|
-
}
|
|
197
|
-
if (options.httpOnly) {
|
|
198
|
-
c.push("HttpOnly");
|
|
199
|
-
}
|
|
200
|
-
if (typeof options.path === "string") {
|
|
201
|
-
c.push(`Path=${options.path}`);
|
|
202
|
-
}
|
|
203
|
-
const sameSite = resolveSameSite(options.sameSite);
|
|
204
|
-
if (sameSite) {
|
|
205
|
-
c.push(`SameSite=${sameSite}`);
|
|
206
|
-
}
|
|
207
|
-
if (options.secure) {
|
|
208
|
-
c.push("Secure");
|
|
209
|
-
}
|
|
210
|
-
return c.join("; ");
|
|
211
|
-
};
|
|
212
|
-
function tryDecodeUriComponent(str) {
|
|
213
|
-
try {
|
|
214
|
-
return decodeURIComponent(str);
|
|
215
|
-
} catch {
|
|
216
|
-
return str;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const parseCookieString = (cookieString) => {
|
|
220
|
-
const cookie = {};
|
|
221
|
-
if (typeof cookieString === "string" && cookieString !== "") {
|
|
222
|
-
const cookieSegments = cookieString.split(";");
|
|
223
|
-
for (const cookieSegment of cookieSegments) {
|
|
224
|
-
const separatorIndex = cookieSegment.indexOf("=");
|
|
225
|
-
if (separatorIndex !== -1) {
|
|
226
|
-
cookie[tryDecodeUriComponent(cookieSegment.slice(0, separatorIndex).trim())] = tryDecodeUriComponent(cookieSegment.slice(separatorIndex + 1).trim());
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return cookie;
|
|
231
|
-
};
|
|
232
|
-
function resolveSameSite(sameSite) {
|
|
233
|
-
if (sameSite === true) {
|
|
234
|
-
return "Strict";
|
|
235
|
-
}
|
|
236
|
-
if (sameSite === false) {
|
|
237
|
-
return "None";
|
|
238
|
-
}
|
|
239
|
-
if (sameSite) {
|
|
240
|
-
return SAMESITE[sameSite];
|
|
241
|
-
}
|
|
242
|
-
return void 0;
|
|
243
|
-
}
|
|
244
|
-
const REQ_COOKIE = Symbol("request-cookies");
|
|
245
|
-
const RES_COOKIE = Symbol("response-cookies");
|
|
246
|
-
const LIVE_COOKIE = Symbol("live-cookies");
|
|
247
|
-
_c = REQ_COOKIE, _b = RES_COOKIE, _a = LIVE_COOKIE;
|
|
248
|
-
class Cookie {
|
|
249
|
-
constructor(cookieString) {
|
|
250
|
-
__publicField(this, _c);
|
|
251
|
-
__publicField(this, _b, {});
|
|
252
|
-
__publicField(this, _a, {});
|
|
253
|
-
__publicField(this, "appendCounter", 0);
|
|
254
|
-
this[REQ_COOKIE] = parseCookieString(cookieString);
|
|
255
|
-
this[LIVE_COOKIE] = { ...this[REQ_COOKIE] };
|
|
256
|
-
}
|
|
257
|
-
get(cookieName, live = true) {
|
|
258
|
-
const value = this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
259
|
-
if (!value) {
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
value,
|
|
264
|
-
json() {
|
|
265
|
-
return JSON.parse(value);
|
|
266
|
-
},
|
|
267
|
-
number() {
|
|
268
|
-
return Number(value);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
getAll(live = true) {
|
|
273
|
-
return Object.keys(this[live ? LIVE_COOKIE : REQ_COOKIE]).reduce(
|
|
274
|
-
(cookies, cookieName) => {
|
|
275
|
-
cookies[cookieName] = this.get(cookieName);
|
|
276
|
-
return cookies;
|
|
277
|
-
},
|
|
278
|
-
{}
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
has(cookieName, live = true) {
|
|
282
|
-
return !!this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
283
|
-
}
|
|
284
|
-
set(cookieName, cookieValue, options = {}) {
|
|
285
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
286
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
287
|
-
this[RES_COOKIE][cookieName] = createSetCookieValue(cookieName, resolvedValue, options);
|
|
288
|
-
}
|
|
289
|
-
append(cookieName, cookieValue, options = {}) {
|
|
290
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
291
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
292
|
-
this[RES_COOKIE][++this.appendCounter] = createSetCookieValue(
|
|
293
|
-
cookieName,
|
|
294
|
-
resolvedValue,
|
|
295
|
-
options
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
delete(name, options) {
|
|
299
|
-
this.set(name, "deleted", { ...options, maxAge: 0 });
|
|
300
|
-
this[LIVE_COOKIE][name] = null;
|
|
301
|
-
}
|
|
302
|
-
headers() {
|
|
303
|
-
return Object.values(this[RES_COOKIE]);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
const mergeHeadersCookies = (headers, cookies) => {
|
|
307
|
-
const cookieHeaders = cookies.headers();
|
|
308
|
-
if (cookieHeaders.length > 0) {
|
|
309
|
-
const newHeaders = new Headers(headers);
|
|
310
|
-
for (const cookie of cookieHeaders) {
|
|
311
|
-
newHeaders.append("Set-Cookie", cookie);
|
|
312
|
-
}
|
|
313
|
-
return newHeaders;
|
|
314
|
-
}
|
|
315
|
-
return headers;
|
|
316
|
-
};
|
|
317
|
-
function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, basePathname = "/") {
|
|
318
|
-
let resolve;
|
|
319
|
-
const responsePromise = new Promise((r) => resolve = r);
|
|
320
|
-
const requestEv = createRequestEvent(
|
|
321
|
-
serverRequestEv,
|
|
322
|
-
loadedRoute,
|
|
323
|
-
requestHandlers,
|
|
324
|
-
basePathname,
|
|
325
|
-
resolve
|
|
326
|
-
);
|
|
327
|
-
return {
|
|
328
|
-
response: responsePromise,
|
|
329
|
-
requestEv,
|
|
330
|
-
completion: requestHandler$1._asyncRequestStore ? requestHandler$1._asyncRequestStore.run(requestEv, runNext, requestEv, rebuildRouteInfo, resolve) : runNext(requestEv, rebuildRouteInfo, resolve)
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
334
|
-
try {
|
|
335
|
-
const isValidURL = (url) => new URL(url.pathname + url.search, url);
|
|
336
|
-
isValidURL(requestEv.originalUrl);
|
|
337
|
-
} catch {
|
|
338
|
-
const status = 404;
|
|
339
|
-
const message = "Resource Not Found";
|
|
340
|
-
requestEv.status(status);
|
|
341
|
-
const html = errorHandler.getErrorHtml(status, message);
|
|
342
|
-
requestEv.html(status, html);
|
|
343
|
-
return new requestHandler$1.ServerError(status, message);
|
|
344
|
-
}
|
|
345
|
-
let rewriteAttempt = 1;
|
|
346
|
-
async function _runNext() {
|
|
347
|
-
try {
|
|
348
|
-
await requestEv.next();
|
|
349
|
-
} catch (e) {
|
|
350
|
-
if (e instanceof requestHandler$1.RedirectMessage) {
|
|
351
|
-
const stream = requestEv.getWritableStream();
|
|
352
|
-
await stream.close();
|
|
353
|
-
return e;
|
|
354
|
-
} else if (e instanceof requestHandler$1.RewriteMessage) {
|
|
355
|
-
if (rewriteAttempt > 50) {
|
|
356
|
-
return new Error(`Infinite rewrite loop`);
|
|
357
|
-
}
|
|
358
|
-
rewriteAttempt += 1;
|
|
359
|
-
const url = new URL(requestEv.url);
|
|
360
|
-
url.pathname = e.pathname;
|
|
361
|
-
const { loadedRoute, requestHandlers } = await rebuildRouteInfo(url);
|
|
362
|
-
requestEv.resetRoute(loadedRoute, requestHandlers, url);
|
|
363
|
-
return await _runNext();
|
|
364
|
-
} else if (e instanceof requestHandler$1.AbortMessage) {
|
|
365
|
-
return;
|
|
366
|
-
} else if (e instanceof requestHandler$1.ServerError && !requestEv.headersSent) {
|
|
367
|
-
const status = e.status;
|
|
368
|
-
const accept = requestEv.request.headers.get("Accept");
|
|
369
|
-
if (accept && !accept.includes("text/html")) {
|
|
370
|
-
requestEv.headers.set("Content-Type", "application/qwik-json");
|
|
371
|
-
requestEv.send(status, await internal._serialize([e.data]));
|
|
372
|
-
} else {
|
|
373
|
-
requestEv.html(status, errorHandler.getErrorHtml(status, e.data));
|
|
374
|
-
}
|
|
375
|
-
return e;
|
|
376
|
-
}
|
|
377
|
-
if (getRequestMode(requestEv) !== "dev") {
|
|
378
|
-
try {
|
|
379
|
-
if (!requestEv.headersSent) {
|
|
380
|
-
requestEv.headers.set("content-type", "text/html; charset=utf-8");
|
|
381
|
-
requestEv.cacheControl({ noCache: true });
|
|
382
|
-
requestEv.status(500);
|
|
383
|
-
}
|
|
384
|
-
const stream = requestEv.getWritableStream();
|
|
385
|
-
if (!stream.locked) {
|
|
386
|
-
const writer = stream.getWriter();
|
|
387
|
-
await writer.write(encoder.encode(errorHandler.getErrorHtml(500, "Internal Server Error")));
|
|
388
|
-
await writer.close();
|
|
389
|
-
}
|
|
390
|
-
} catch {
|
|
391
|
-
console.error("Unable to render error page");
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return e;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
return await _runNext();
|
|
399
|
-
} finally {
|
|
400
|
-
if (!requestEv.isDirty()) {
|
|
401
|
-
resolve(null);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
function getRouteMatchPathname(pathname) {
|
|
406
|
-
const isInternal = pathname.endsWith(QDATA_JSON);
|
|
407
|
-
if (isInternal) {
|
|
408
|
-
const trimEnd = pathname.length - QDATA_JSON.length + (globalThis.__NO_TRAILING_SLASH__ ? 0 : 1);
|
|
409
|
-
pathname = pathname.slice(0, trimEnd);
|
|
410
|
-
if (pathname === "") {
|
|
411
|
-
pathname = "/";
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return { pathname, isInternal };
|
|
415
|
-
}
|
|
416
|
-
const IsQData = "@isQData";
|
|
417
|
-
const QDATA_JSON = "/q-data.json";
|
|
418
|
-
const RequestEvLoaders = Symbol("RequestEvLoaders");
|
|
419
|
-
const RequestEvMode = Symbol("RequestEvMode");
|
|
420
|
-
const RequestEvRoute = Symbol("RequestEvRoute");
|
|
421
|
-
const RequestEvLoaderSerializationStrategyMap = Symbol(
|
|
422
|
-
"RequestEvLoaderSerializationStrategyMap"
|
|
423
|
-
);
|
|
424
|
-
const RequestRouteName = "@routeName";
|
|
425
|
-
const RequestEvSharedActionId = "@actionId";
|
|
426
|
-
const RequestEvSharedActionFormData = "@actionFormData";
|
|
427
|
-
const RequestEvSharedNonce = "@nonce";
|
|
428
|
-
const RequestEvIsRewrite = "@rewrite";
|
|
429
|
-
const RequestEvShareServerTiming = "@serverTiming";
|
|
430
|
-
const RequestEvShareQData = "qData";
|
|
431
|
-
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, basePathname, resolved) {
|
|
432
|
-
const { request, platform, env } = serverRequestEv;
|
|
433
|
-
const sharedMap = /* @__PURE__ */ new Map();
|
|
434
|
-
const cookie = new Cookie(request.headers.get("cookie"));
|
|
435
|
-
const headers = new Headers();
|
|
436
|
-
const url = new URL(request.url);
|
|
437
|
-
const { pathname, isInternal } = getRouteMatchPathname(url.pathname);
|
|
438
|
-
if (isInternal) {
|
|
439
|
-
url.pathname = pathname;
|
|
440
|
-
sharedMap.set(IsQData, true);
|
|
441
|
-
}
|
|
442
|
-
let routeModuleIndex = -1;
|
|
443
|
-
let writableStream = null;
|
|
444
|
-
let requestData = void 0;
|
|
445
|
-
let locale = serverRequestEv.locale;
|
|
446
|
-
let status = 200;
|
|
447
|
-
const next = async () => {
|
|
448
|
-
routeModuleIndex++;
|
|
449
|
-
while (routeModuleIndex < requestHandlers.length) {
|
|
450
|
-
const moduleRequestHandler = requestHandlers[routeModuleIndex];
|
|
451
|
-
const result = moduleRequestHandler(requestEv);
|
|
452
|
-
if (routing.isPromise(result)) {
|
|
453
|
-
await result;
|
|
454
|
-
}
|
|
455
|
-
routeModuleIndex++;
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
const resetRoute = (_loadedRoute, _requestHandlers, _url = url) => {
|
|
459
|
-
loadedRoute = _loadedRoute;
|
|
460
|
-
requestHandlers = _requestHandlers;
|
|
461
|
-
url.pathname = _url.pathname;
|
|
462
|
-
url.search = _url.search;
|
|
463
|
-
routeModuleIndex = -1;
|
|
464
|
-
};
|
|
465
|
-
const check = () => {
|
|
466
|
-
if (writableStream !== null) {
|
|
467
|
-
throw new Error("Response already sent");
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
const send = (statusOrResponse, body) => {
|
|
471
|
-
check();
|
|
472
|
-
if (typeof statusOrResponse === "number") {
|
|
473
|
-
status = statusOrResponse;
|
|
474
|
-
const writableStream2 = requestEv.getWritableStream();
|
|
475
|
-
const writer = writableStream2.getWriter();
|
|
476
|
-
writer.write(typeof body === "string" ? encoder.encode(body) : body);
|
|
477
|
-
writer.close();
|
|
478
|
-
} else {
|
|
479
|
-
status = statusOrResponse.status;
|
|
480
|
-
statusOrResponse.headers.forEach((value, key) => {
|
|
481
|
-
if (key.toLowerCase() === "set-cookie") {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
headers.append(key, value);
|
|
485
|
-
});
|
|
486
|
-
statusOrResponse.headers.getSetCookie().forEach((ck) => {
|
|
487
|
-
const index = ck.indexOf("=");
|
|
488
|
-
if (index === -1) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
const key = ck.slice(0, index).trim();
|
|
492
|
-
const value = ck.slice(index + 1).trim();
|
|
493
|
-
cookie.set(key, value);
|
|
494
|
-
});
|
|
495
|
-
if (statusOrResponse.body) {
|
|
496
|
-
const writableStream2 = requestEv.getWritableStream();
|
|
497
|
-
statusOrResponse.body.pipeTo(writableStream2);
|
|
498
|
-
} else {
|
|
499
|
-
requestEv.getWritableStream().getWriter().close();
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return exit();
|
|
503
|
-
};
|
|
504
|
-
const exit = (message = new requestHandler$1.AbortMessage()) => {
|
|
505
|
-
routeModuleIndex = ABORT_INDEX;
|
|
506
|
-
return message;
|
|
507
|
-
};
|
|
508
|
-
const loaders = {};
|
|
509
|
-
const requestEv = {
|
|
510
|
-
[RequestEvLoaders]: loaders,
|
|
511
|
-
[RequestEvLoaderSerializationStrategyMap]: /* @__PURE__ */ new Map(),
|
|
512
|
-
[RequestEvMode]: serverRequestEv.mode,
|
|
513
|
-
get [RequestEvRoute]() {
|
|
514
|
-
return loadedRoute;
|
|
515
|
-
},
|
|
516
|
-
cookie,
|
|
517
|
-
headers,
|
|
518
|
-
env,
|
|
519
|
-
method: request.method,
|
|
520
|
-
signal: request.signal,
|
|
521
|
-
originalUrl: new URL(url),
|
|
522
|
-
get params() {
|
|
523
|
-
return loadedRoute?.[types.LoadedRouteProp.Params] ?? {};
|
|
524
|
-
},
|
|
525
|
-
get pathname() {
|
|
526
|
-
return url.pathname;
|
|
527
|
-
},
|
|
528
|
-
platform,
|
|
529
|
-
get query() {
|
|
530
|
-
return url.searchParams;
|
|
531
|
-
},
|
|
532
|
-
request,
|
|
533
|
-
url,
|
|
534
|
-
basePathname,
|
|
535
|
-
sharedMap,
|
|
536
|
-
get headersSent() {
|
|
537
|
-
return writableStream !== null;
|
|
538
|
-
},
|
|
539
|
-
get exited() {
|
|
540
|
-
return routeModuleIndex >= ABORT_INDEX;
|
|
541
|
-
},
|
|
542
|
-
get clientConn() {
|
|
543
|
-
return serverRequestEv.getClientConn();
|
|
544
|
-
},
|
|
545
|
-
next,
|
|
546
|
-
resetRoute,
|
|
547
|
-
exit,
|
|
548
|
-
cacheControl: (cacheControl, target = "Cache-Control") => {
|
|
549
|
-
check();
|
|
550
|
-
headers.set(target, createCacheControl(cacheControl));
|
|
551
|
-
},
|
|
552
|
-
resolveValue: (async (loaderOrAction) => {
|
|
553
|
-
const id = loaderOrAction.__id;
|
|
554
|
-
if (loaderOrAction.__brand === "server_loader") {
|
|
555
|
-
if (!(id in loaders)) {
|
|
556
|
-
throw new Error(
|
|
557
|
-
"You can not get the returned data of a loader that has not been executed for this request."
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
if (loaders[id] === internal._UNINITIALIZED) {
|
|
561
|
-
const isDev = getRequestMode(requestEv) === "dev";
|
|
562
|
-
await getRouteLoaderPromise(loaderOrAction, loaders, requestEv, isDev);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return loaders[id];
|
|
566
|
-
}),
|
|
567
|
-
status: (statusCode) => {
|
|
568
|
-
if (typeof statusCode === "number") {
|
|
569
|
-
check();
|
|
570
|
-
status = statusCode;
|
|
571
|
-
return statusCode;
|
|
572
|
-
}
|
|
573
|
-
return status;
|
|
574
|
-
},
|
|
575
|
-
locale: (_locale) => {
|
|
576
|
-
if (typeof _locale === "string") {
|
|
577
|
-
locale = _locale;
|
|
578
|
-
}
|
|
579
|
-
return locale || "";
|
|
580
|
-
},
|
|
581
|
-
error: (statusCode, message) => {
|
|
582
|
-
status = statusCode;
|
|
583
|
-
headers.delete("Cache-Control");
|
|
584
|
-
return new requestHandler$1.ServerError(statusCode, message);
|
|
585
|
-
},
|
|
586
|
-
redirect: (statusCode, url2) => {
|
|
587
|
-
check();
|
|
588
|
-
status = statusCode;
|
|
589
|
-
if (url2) {
|
|
590
|
-
if (/([^:])\/{2,}/.test(url2)) {
|
|
591
|
-
const fixedURL = url2.replace(/([^:])\/{2,}/g, "$1/");
|
|
592
|
-
console.warn(`Redirect URL ${url2} is invalid, fixing to ${fixedURL}`);
|
|
593
|
-
url2 = fixedURL;
|
|
594
|
-
}
|
|
595
|
-
headers.set("Location", url2);
|
|
596
|
-
}
|
|
597
|
-
headers.delete("Cache-Control");
|
|
598
|
-
if (statusCode > 301) {
|
|
599
|
-
headers.set("Cache-Control", "no-store");
|
|
600
|
-
}
|
|
601
|
-
return exit(new requestHandler$1.RedirectMessage());
|
|
602
|
-
},
|
|
603
|
-
rewrite: (pathname2) => {
|
|
604
|
-
check();
|
|
605
|
-
if (pathname2.startsWith("http")) {
|
|
606
|
-
throw new Error("Rewrite does not support absolute urls");
|
|
607
|
-
}
|
|
608
|
-
sharedMap.set(RequestEvIsRewrite, true);
|
|
609
|
-
return exit(new requestHandler$1.RewriteMessage(pathname2.replace(/\/+/g, "/")));
|
|
610
|
-
},
|
|
611
|
-
defer: (returnData) => {
|
|
612
|
-
return typeof returnData === "function" ? returnData : () => returnData;
|
|
613
|
-
},
|
|
614
|
-
fail: (statusCode, data) => {
|
|
615
|
-
check();
|
|
616
|
-
status = statusCode;
|
|
617
|
-
headers.delete("Cache-Control");
|
|
618
|
-
return {
|
|
619
|
-
failed: true,
|
|
620
|
-
...data
|
|
621
|
-
};
|
|
622
|
-
},
|
|
623
|
-
text: (statusCode, text) => {
|
|
624
|
-
headers.set("Content-Type", "text/plain; charset=utf-8");
|
|
625
|
-
return send(statusCode, text);
|
|
626
|
-
},
|
|
627
|
-
html: (statusCode, html) => {
|
|
628
|
-
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
629
|
-
return send(statusCode, html);
|
|
630
|
-
},
|
|
631
|
-
parseBody: async () => {
|
|
632
|
-
if (requestData !== void 0) {
|
|
633
|
-
return requestData;
|
|
634
|
-
}
|
|
635
|
-
return requestData = parseRequest(requestEv, sharedMap);
|
|
636
|
-
},
|
|
637
|
-
json: (statusCode, data) => {
|
|
638
|
-
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
639
|
-
return send(statusCode, JSON.stringify(data));
|
|
640
|
-
},
|
|
641
|
-
send,
|
|
642
|
-
isDirty: () => {
|
|
643
|
-
return writableStream !== null;
|
|
644
|
-
},
|
|
645
|
-
getWritableStream: () => {
|
|
646
|
-
if (writableStream === null) {
|
|
647
|
-
if (serverRequestEv.mode === "dev") {
|
|
648
|
-
const serverTiming = sharedMap.get(RequestEvShareServerTiming);
|
|
649
|
-
if (serverTiming) {
|
|
650
|
-
headers.set(
|
|
651
|
-
"Server-Timing",
|
|
652
|
-
serverTiming.map(([name, duration]) => `${name};dur=${duration}`).join(",")
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
writableStream = serverRequestEv.getWritableStream(
|
|
657
|
-
status,
|
|
658
|
-
headers,
|
|
659
|
-
cookie,
|
|
660
|
-
resolved,
|
|
661
|
-
requestEv
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
return writableStream;
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
return Object.freeze(requestEv);
|
|
668
|
-
}
|
|
669
|
-
function getRequestLoaders(requestEv) {
|
|
670
|
-
return requestEv[RequestEvLoaders];
|
|
671
|
-
}
|
|
672
|
-
function getRequestLoaderSerializationStrategyMap(requestEv) {
|
|
673
|
-
return requestEv[RequestEvLoaderSerializationStrategyMap];
|
|
674
|
-
}
|
|
675
|
-
function getRequestRoute(requestEv) {
|
|
676
|
-
return requestEv[RequestEvRoute];
|
|
677
|
-
}
|
|
678
|
-
function getRequestMode(requestEv) {
|
|
679
|
-
return requestEv[RequestEvMode];
|
|
680
|
-
}
|
|
681
|
-
const ABORT_INDEX = Number.MAX_SAFE_INTEGER;
|
|
682
|
-
const parseRequest = async ({ request, method, query }, sharedMap) => {
|
|
683
|
-
const type = request.headers.get("content-type")?.split(/[;,]/, 1)[0].trim() ?? "";
|
|
684
|
-
if (type === "application/x-www-form-urlencoded" || type === "multipart/form-data") {
|
|
685
|
-
const formData = await request.formData();
|
|
686
|
-
sharedMap.set(RequestEvSharedActionFormData, formData);
|
|
687
|
-
return formToObj(formData);
|
|
688
|
-
} else if (type === "application/json") {
|
|
689
|
-
const data = await request.json();
|
|
690
|
-
return data;
|
|
691
|
-
} else if (type === "application/qwik-json") {
|
|
692
|
-
if (method === "GET" && query.has(routing.QDATA_KEY)) {
|
|
693
|
-
const data = query.get(routing.QDATA_KEY);
|
|
694
|
-
if (data) {
|
|
695
|
-
try {
|
|
696
|
-
return internal._deserialize(decodeURIComponent(data));
|
|
697
|
-
} catch {
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return internal._deserialize(await request.text());
|
|
702
|
-
}
|
|
703
|
-
return void 0;
|
|
704
|
-
};
|
|
705
|
-
const formToObj = (formData) => {
|
|
706
|
-
const values = [...formData.entries()].reduce((values2, [name, value]) => {
|
|
707
|
-
name.split(".").reduce((object, key, index, keys) => {
|
|
708
|
-
if (key.endsWith("[]")) {
|
|
709
|
-
const arrayKey = key.slice(0, -2);
|
|
710
|
-
object[arrayKey] = object[arrayKey] || [];
|
|
711
|
-
return object[arrayKey] = [...object[arrayKey], value];
|
|
712
|
-
}
|
|
713
|
-
if (index < keys.length - 1) {
|
|
714
|
-
return object[key] = object[key] || (Number.isNaN(+keys[index + 1]) ? {} : []);
|
|
715
|
-
}
|
|
716
|
-
return object[key] = value;
|
|
717
|
-
}, values2);
|
|
718
|
-
return values2;
|
|
719
|
-
}, {});
|
|
720
|
-
return values;
|
|
721
|
-
};
|
|
722
|
-
function getQwikRouterServerData(requestEv) {
|
|
723
|
-
const { params, request, status, locale, originalUrl } = requestEv;
|
|
724
|
-
const requestHeaders = {};
|
|
725
|
-
request.headers.forEach((value, key) => requestHeaders[key] = value);
|
|
726
|
-
const action = requestEv.sharedMap.get(RequestEvSharedActionId);
|
|
727
|
-
const formData = requestEv.sharedMap.get(RequestEvSharedActionFormData);
|
|
728
|
-
const routeName = requestEv.sharedMap.get(RequestRouteName);
|
|
729
|
-
const nonce = requestEv.sharedMap.get(RequestEvSharedNonce);
|
|
730
|
-
const headers = requestEv.request.headers;
|
|
731
|
-
const reconstructedUrl = new URL(originalUrl.pathname + originalUrl.search, originalUrl);
|
|
732
|
-
const host = headers.get("X-Forwarded-Host");
|
|
733
|
-
const protocol = headers.get("X-Forwarded-Proto");
|
|
734
|
-
if (host) {
|
|
735
|
-
reconstructedUrl.port = "";
|
|
736
|
-
reconstructedUrl.host = host;
|
|
737
|
-
}
|
|
738
|
-
if (protocol) {
|
|
739
|
-
reconstructedUrl.protocol = protocol;
|
|
740
|
-
}
|
|
741
|
-
const loaders = getRequestLoaders(requestEv);
|
|
742
|
-
const loadersSerializationStrategy = getRequestLoaderSerializationStrategyMap(requestEv);
|
|
743
|
-
return {
|
|
744
|
-
url: reconstructedUrl.href,
|
|
745
|
-
requestHeaders,
|
|
746
|
-
locale: locale(),
|
|
747
|
-
nonce,
|
|
748
|
-
containerAttributes: {
|
|
749
|
-
[routing.Q_ROUTE]: routeName
|
|
750
|
-
},
|
|
751
|
-
qwikrouter: {
|
|
752
|
-
routeName,
|
|
753
|
-
ev: requestEv,
|
|
754
|
-
params: { ...params },
|
|
755
|
-
loadedRoute: getRequestRoute(requestEv),
|
|
756
|
-
response: {
|
|
757
|
-
status: status(),
|
|
758
|
-
loaders,
|
|
759
|
-
loadersSerializationStrategy,
|
|
760
|
-
action,
|
|
761
|
-
formData
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
const resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderHandler, isInternal) => {
|
|
767
|
-
const routeLoaders = [];
|
|
768
|
-
const routeActions = [];
|
|
769
|
-
const requestHandlers = [];
|
|
770
|
-
const isPageRoute = !!(route && isLastModulePageRoute(route[types.LoadedRouteProp.Mods]));
|
|
771
|
-
if (isInternal) {
|
|
772
|
-
requestHandlers.push(handleQDataRedirect);
|
|
773
|
-
}
|
|
774
|
-
if (serverPlugins) {
|
|
775
|
-
_resolveRequestHandlers(
|
|
776
|
-
routeLoaders,
|
|
777
|
-
routeActions,
|
|
778
|
-
requestHandlers,
|
|
779
|
-
serverPlugins,
|
|
780
|
-
isPageRoute,
|
|
781
|
-
method
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
if (route) {
|
|
785
|
-
const routeModules = route[types.LoadedRouteProp.Mods];
|
|
786
|
-
_resolveRequestHandlers(
|
|
787
|
-
routeLoaders,
|
|
788
|
-
routeActions,
|
|
789
|
-
requestHandlers,
|
|
790
|
-
routeModules,
|
|
791
|
-
isPageRoute,
|
|
792
|
-
method
|
|
793
|
-
);
|
|
794
|
-
const routeName = route[types.LoadedRouteProp.RouteName];
|
|
795
|
-
if (checkOrigin && (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE")) {
|
|
796
|
-
if (checkOrigin === "lax-proto") {
|
|
797
|
-
requestHandlers.unshift(csrfLaxProtoCheckMiddleware);
|
|
798
|
-
} else {
|
|
799
|
-
requestHandlers.unshift(csrfCheckMiddleware);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
if (isPageRoute) {
|
|
803
|
-
if (method === "POST" || method === "GET") {
|
|
804
|
-
requestHandlers.push(runServerFunction);
|
|
805
|
-
}
|
|
806
|
-
requestHandlers.push(fixTrailingSlash);
|
|
807
|
-
if (isInternal) {
|
|
808
|
-
requestHandlers.push(renderQData);
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
if (isPageRoute) {
|
|
812
|
-
requestHandlers.push((ev) => {
|
|
813
|
-
ev.sharedMap.set(RequestRouteName, routeName);
|
|
814
|
-
});
|
|
815
|
-
requestHandlers.push(actionsMiddleware(routeActions));
|
|
816
|
-
requestHandlers.push(loadersMiddleware(routeLoaders));
|
|
817
|
-
requestHandlers.push(renderHandler);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return requestHandlers;
|
|
821
|
-
};
|
|
822
|
-
const _resolveRequestHandlers = (routeLoaders, routeActions, requestHandlers, routeModules, collectActions, method) => {
|
|
823
|
-
for (const routeModule of routeModules) {
|
|
824
|
-
if (typeof routeModule.onRequest === "function") {
|
|
825
|
-
requestHandlers.push(routeModule.onRequest);
|
|
826
|
-
} else if (Array.isArray(routeModule.onRequest)) {
|
|
827
|
-
requestHandlers.push(...routeModule.onRequest);
|
|
828
|
-
}
|
|
829
|
-
let methodReqHandler;
|
|
830
|
-
switch (method) {
|
|
831
|
-
case "GET": {
|
|
832
|
-
methodReqHandler = routeModule.onGet;
|
|
833
|
-
break;
|
|
834
|
-
}
|
|
835
|
-
case "POST": {
|
|
836
|
-
methodReqHandler = routeModule.onPost;
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
case "PUT": {
|
|
840
|
-
methodReqHandler = routeModule.onPut;
|
|
841
|
-
break;
|
|
842
|
-
}
|
|
843
|
-
case "PATCH": {
|
|
844
|
-
methodReqHandler = routeModule.onPatch;
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
case "DELETE": {
|
|
848
|
-
methodReqHandler = routeModule.onDelete;
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
case "OPTIONS": {
|
|
852
|
-
methodReqHandler = routeModule.onOptions;
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
case "HEAD": {
|
|
856
|
-
methodReqHandler = routeModule.onHead;
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
if (typeof methodReqHandler === "function") {
|
|
861
|
-
requestHandlers.push(methodReqHandler);
|
|
862
|
-
} else if (Array.isArray(methodReqHandler)) {
|
|
863
|
-
requestHandlers.push(...methodReqHandler);
|
|
864
|
-
}
|
|
865
|
-
if (collectActions) {
|
|
866
|
-
for (const module2 of Object.values(routeModule)) {
|
|
867
|
-
if (typeof module2 === "function") {
|
|
868
|
-
if (module2.__brand === "server_loader") {
|
|
869
|
-
routeLoaders.push(module2);
|
|
870
|
-
} else if (module2.__brand === "server_action") {
|
|
871
|
-
routeActions.push(module2);
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
function actionsMiddleware(routeActions) {
|
|
879
|
-
return async (requestEvent) => {
|
|
880
|
-
const requestEv = requestEvent;
|
|
881
|
-
if (requestEv.headersSent) {
|
|
882
|
-
requestEv.exit();
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
const { method } = requestEv;
|
|
886
|
-
const loaders = getRequestLoaders(requestEv);
|
|
887
|
-
const isDev = getRequestMode(requestEv) === "dev";
|
|
888
|
-
if (isDev && method === "GET") {
|
|
889
|
-
if (requestEv.query.has(routing.QACTION_KEY)) {
|
|
890
|
-
console.warn(
|
|
891
|
-
'Seems like you are submitting a Qwik Action via GET request. Qwik Actions should be submitted via POST request.\nMake sure your <form> has method="POST" attribute, like this: <form method="POST">'
|
|
892
|
-
);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
if (method === "POST") {
|
|
896
|
-
const selectedActionId = requestEv.query.get(routing.QACTION_KEY);
|
|
897
|
-
if (selectedActionId) {
|
|
898
|
-
const serverActionsMap = globalThis._qwikActionsMap;
|
|
899
|
-
const action = routeActions.find((action2) => action2.__id === selectedActionId) ?? serverActionsMap?.get(selectedActionId);
|
|
900
|
-
if (action) {
|
|
901
|
-
requestEv.sharedMap.set(RequestEvSharedActionId, selectedActionId);
|
|
902
|
-
const data = await requestEv.parseBody();
|
|
903
|
-
if (!data || typeof data !== "object") {
|
|
904
|
-
throw new Error(
|
|
905
|
-
`Expected request data for the action id ${selectedActionId} to be an object`
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
const result = await runValidators(requestEv, action.__validators, data, isDev);
|
|
909
|
-
if (!result.success) {
|
|
910
|
-
loaders[selectedActionId] = requestEv.fail(result.status ?? 500, result.error);
|
|
911
|
-
} else {
|
|
912
|
-
const actionResolved = isDev ? await measure(
|
|
913
|
-
requestEv,
|
|
914
|
-
action.__qrl.getHash(),
|
|
915
|
-
() => action.__qrl.call(requestEv, result.data, requestEv)
|
|
916
|
-
) : await action.__qrl.call(requestEv, result.data, requestEv);
|
|
917
|
-
if (isDev) {
|
|
918
|
-
verifySerializable(actionResolved, action.__qrl);
|
|
919
|
-
}
|
|
920
|
-
loaders[selectedActionId] = actionResolved;
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
function loadersMiddleware(routeLoaders) {
|
|
928
|
-
return async (requestEvent) => {
|
|
929
|
-
const requestEv = requestEvent;
|
|
930
|
-
if (requestEv.headersSent) {
|
|
931
|
-
requestEv.exit();
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
const loaders = getRequestLoaders(requestEv);
|
|
935
|
-
const isDev = getRequestMode(requestEv) === "dev";
|
|
936
|
-
if (routeLoaders.length > 0) {
|
|
937
|
-
const resolvedLoadersPromises = routeLoaders.map(
|
|
938
|
-
(loader) => getRouteLoaderPromise(loader, loaders, requestEv, isDev)
|
|
939
|
-
);
|
|
940
|
-
await Promise.all(resolvedLoadersPromises);
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
async function getRouteLoaderPromise(loader, loaders, requestEv, isDev) {
|
|
945
|
-
const loaderId = loader.__id;
|
|
946
|
-
loaders[loaderId] = runValidators(
|
|
947
|
-
requestEv,
|
|
948
|
-
loader.__validators,
|
|
949
|
-
void 0,
|
|
950
|
-
// data
|
|
951
|
-
isDev
|
|
952
|
-
).then((res) => {
|
|
953
|
-
if (res.success) {
|
|
954
|
-
if (isDev) {
|
|
955
|
-
return measure(
|
|
956
|
-
requestEv,
|
|
957
|
-
loader.__qrl.getHash(),
|
|
958
|
-
() => loader.__qrl.call(requestEv, requestEv)
|
|
959
|
-
);
|
|
960
|
-
} else {
|
|
961
|
-
return loader.__qrl.call(requestEv, requestEv);
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
return requestEv.fail(res.status ?? 500, res.error);
|
|
965
|
-
}
|
|
966
|
-
}).then((resolvedLoader) => {
|
|
967
|
-
if (typeof resolvedLoader === "function") {
|
|
968
|
-
loaders[loaderId] = resolvedLoader();
|
|
969
|
-
} else {
|
|
970
|
-
if (isDev) {
|
|
971
|
-
verifySerializable(resolvedLoader, loader.__qrl);
|
|
972
|
-
}
|
|
973
|
-
loaders[loaderId] = resolvedLoader;
|
|
974
|
-
}
|
|
975
|
-
return resolvedLoader;
|
|
976
|
-
});
|
|
977
|
-
const loadersSerializationStrategy = getRequestLoaderSerializationStrategyMap(requestEv);
|
|
978
|
-
loadersSerializationStrategy.set(loaderId, loader.__serializationStrategy);
|
|
979
|
-
return loaders[loaderId];
|
|
980
|
-
}
|
|
981
|
-
async function runValidators(requestEv, validators, data, isDev) {
|
|
982
|
-
let lastResult = {
|
|
983
|
-
success: true,
|
|
984
|
-
data
|
|
985
|
-
};
|
|
986
|
-
if (validators) {
|
|
987
|
-
for (const validator of validators) {
|
|
988
|
-
if (isDev) {
|
|
989
|
-
lastResult = await measure(
|
|
990
|
-
requestEv,
|
|
991
|
-
`validator$`,
|
|
992
|
-
() => validator.validate(requestEv, data)
|
|
993
|
-
);
|
|
994
|
-
} else {
|
|
995
|
-
lastResult = await validator.validate(requestEv, data);
|
|
996
|
-
}
|
|
997
|
-
if (!lastResult.success) {
|
|
998
|
-
return lastResult;
|
|
999
|
-
} else {
|
|
1000
|
-
data = lastResult.data;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
return lastResult;
|
|
1005
|
-
}
|
|
1006
|
-
function isAsyncIterator(obj) {
|
|
1007
|
-
return obj ? typeof obj === "object" && Symbol.asyncIterator in obj : false;
|
|
1008
|
-
}
|
|
1009
|
-
async function runServerFunction(ev) {
|
|
1010
|
-
const serverFnHash = ev.query.get(routing.QFN_KEY);
|
|
1011
|
-
if (serverFnHash && ev.request.headers.get("X-QRL") === serverFnHash && ev.request.headers.get("Content-Type") === "application/qwik-json") {
|
|
1012
|
-
ev.exit();
|
|
1013
|
-
const isDev = getRequestMode(ev) === "dev";
|
|
1014
|
-
const data = await ev.parseBody();
|
|
1015
|
-
if (Array.isArray(data)) {
|
|
1016
|
-
const qrl = core.inlinedQrl(null, serverFnHash, data[1]);
|
|
1017
|
-
let result;
|
|
1018
|
-
try {
|
|
1019
|
-
if (isDev) {
|
|
1020
|
-
result = await measure(
|
|
1021
|
-
ev,
|
|
1022
|
-
`server_${serverFnHash}`,
|
|
1023
|
-
() => qrl.apply(ev, data[0])
|
|
1024
|
-
);
|
|
1025
|
-
} else {
|
|
1026
|
-
result = await qrl.apply(ev, data[0]);
|
|
1027
|
-
}
|
|
1028
|
-
} catch (err) {
|
|
1029
|
-
if (err instanceof requestHandler$1.ServerError) {
|
|
1030
|
-
throw ev.error(err.status, err.data);
|
|
1031
|
-
}
|
|
1032
|
-
console.error(`Server function ${serverFnHash} failed:`, err);
|
|
1033
|
-
throw ev.error(500, "Invalid request");
|
|
1034
|
-
}
|
|
1035
|
-
if (isAsyncIterator(result)) {
|
|
1036
|
-
ev.headers.set("Content-Type", "text/qwik-json-stream");
|
|
1037
|
-
const writable = ev.getWritableStream();
|
|
1038
|
-
const stream = writable.getWriter();
|
|
1039
|
-
for await (const item of result) {
|
|
1040
|
-
if (isDev) {
|
|
1041
|
-
verifySerializable(item, qrl);
|
|
1042
|
-
}
|
|
1043
|
-
const message = await internal._serialize([item]);
|
|
1044
|
-
if (ev.signal.aborted) {
|
|
1045
|
-
break;
|
|
1046
|
-
}
|
|
1047
|
-
await stream.write(encoder.encode(`${message}
|
|
1048
|
-
`));
|
|
1049
|
-
}
|
|
1050
|
-
stream.close();
|
|
1051
|
-
} else {
|
|
1052
|
-
verifySerializable(result, qrl);
|
|
1053
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
1054
|
-
const message = await internal._serialize([result]);
|
|
1055
|
-
ev.send(200, message);
|
|
1056
|
-
}
|
|
1057
|
-
return;
|
|
1058
|
-
}
|
|
1059
|
-
throw ev.error(500, "Invalid request");
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
function fixTrailingSlash(ev) {
|
|
1063
|
-
const { basePathname, originalUrl, sharedMap } = ev;
|
|
1064
|
-
const { pathname, search } = originalUrl;
|
|
1065
|
-
const isQData = sharedMap.has(IsQData);
|
|
1066
|
-
if (!isQData && pathname !== basePathname && !pathname.endsWith(".html")) {
|
|
1067
|
-
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1068
|
-
if (!pathname.endsWith("/")) {
|
|
1069
|
-
throw ev.redirect(HttpStatus.MovedPermanently, pathname + "/" + search);
|
|
1070
|
-
}
|
|
1071
|
-
} else {
|
|
1072
|
-
if (pathname.endsWith("/")) {
|
|
1073
|
-
throw ev.redirect(
|
|
1074
|
-
HttpStatus.MovedPermanently,
|
|
1075
|
-
pathname.slice(0, pathname.length - 1) + search
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
function verifySerializable(data, qrl) {
|
|
1082
|
-
try {
|
|
1083
|
-
internal._verifySerializable(data, void 0);
|
|
1084
|
-
} catch (e) {
|
|
1085
|
-
if (e instanceof Error && qrl.dev) {
|
|
1086
|
-
e.loc = qrl.dev;
|
|
1087
|
-
}
|
|
1088
|
-
throw e;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
function isLastModulePageRoute(routeModules) {
|
|
1092
|
-
const lastRouteModule = routeModules[routeModules.length - 1];
|
|
1093
|
-
return lastRouteModule && typeof lastRouteModule.default === "function";
|
|
1094
|
-
}
|
|
1095
|
-
function getPathname(url) {
|
|
1096
|
-
url = new URL(url);
|
|
1097
|
-
if (url.pathname.endsWith(QDATA_JSON)) {
|
|
1098
|
-
url.pathname = url.pathname.slice(0, -QDATA_JSON.length);
|
|
1099
|
-
}
|
|
1100
|
-
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1101
|
-
if (!url.pathname.endsWith("/")) {
|
|
1102
|
-
url.pathname += "/";
|
|
1103
|
-
}
|
|
1104
|
-
} else {
|
|
1105
|
-
if (url.pathname.endsWith("/")) {
|
|
1106
|
-
url.pathname = url.pathname.slice(0, -1);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
const search = url.search.slice(1).replaceAll(/&?q(action|data|func|loaders)=[^&]+/g, "");
|
|
1110
|
-
return `${url.pathname}${search ? `?${search}` : ""}${url.hash}`;
|
|
1111
|
-
}
|
|
1112
|
-
const encoder = /* @__PURE__ */ new TextEncoder();
|
|
1113
|
-
function csrfLaxProtoCheckMiddleware(requestEv) {
|
|
1114
|
-
checkCSRF(requestEv, "lax-proto");
|
|
1115
|
-
}
|
|
1116
|
-
function csrfCheckMiddleware(requestEv) {
|
|
1117
|
-
checkCSRF(requestEv);
|
|
1118
|
-
}
|
|
1119
|
-
function checkCSRF(requestEv, laxProto) {
|
|
1120
|
-
const isForm = isContentType(
|
|
1121
|
-
requestEv.request.headers,
|
|
1122
|
-
"application/x-www-form-urlencoded",
|
|
1123
|
-
"multipart/form-data",
|
|
1124
|
-
"text/plain"
|
|
1125
|
-
);
|
|
1126
|
-
if (isForm) {
|
|
1127
|
-
const inputOrigin = requestEv.request.headers.get("origin");
|
|
1128
|
-
const origin = requestEv.url.origin;
|
|
1129
|
-
let forbidden = inputOrigin !== origin;
|
|
1130
|
-
if (forbidden && laxProto && inputOrigin?.replace(/^http(s)?/g, "") === origin.replace(/^http(s)?/g, "")) {
|
|
1131
|
-
forbidden = false;
|
|
1132
|
-
}
|
|
1133
|
-
if (forbidden) {
|
|
1134
|
-
throw requestEv.error(
|
|
1135
|
-
403,
|
|
1136
|
-
`CSRF check failed. Cross-site ${requestEv.method} form submissions are forbidden.
|
|
1137
|
-
The request origin "${inputOrigin}" does not match the server origin "${origin}".`
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
function renderQwikMiddleware(render) {
|
|
1143
|
-
return async (requestEv) => {
|
|
1144
|
-
if (requestEv.headersSent) {
|
|
1145
|
-
return;
|
|
1146
|
-
}
|
|
1147
|
-
const isPageDataReq = requestEv.sharedMap.has(IsQData);
|
|
1148
|
-
if (isPageDataReq) {
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
requestEv.request.headers.forEach((value, key) => value);
|
|
1152
|
-
const responseHeaders = requestEv.headers;
|
|
1153
|
-
if (!responseHeaders.has("Content-Type")) {
|
|
1154
|
-
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
|
|
1155
|
-
}
|
|
1156
|
-
const { readable, writable } = new TextEncoderStream();
|
|
1157
|
-
const writableStream = requestEv.getWritableStream();
|
|
1158
|
-
const pipe = readable.pipeTo(writableStream, { preventClose: true });
|
|
1159
|
-
const stream = writable.getWriter();
|
|
1160
|
-
const status = requestEv.status();
|
|
1161
|
-
try {
|
|
1162
|
-
const isStatic = getRequestMode(requestEv) === "static";
|
|
1163
|
-
const serverData = getQwikRouterServerData(requestEv);
|
|
1164
|
-
const result = await render({
|
|
1165
|
-
base: requestEv.basePathname + "build/",
|
|
1166
|
-
stream,
|
|
1167
|
-
serverData,
|
|
1168
|
-
containerAttributes: {
|
|
1169
|
-
["q:render"]: isStatic ? "static" : "",
|
|
1170
|
-
...serverData.containerAttributes
|
|
1171
|
-
}
|
|
1172
|
-
});
|
|
1173
|
-
const qData = {
|
|
1174
|
-
loaders: getRequestLoaders(requestEv),
|
|
1175
|
-
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1176
|
-
status: status !== 200 ? status : 200,
|
|
1177
|
-
href: getPathname(requestEv.url)
|
|
1178
|
-
};
|
|
1179
|
-
if (typeof result.html === "string") {
|
|
1180
|
-
await stream.write(result.html);
|
|
1181
|
-
}
|
|
1182
|
-
requestEv.sharedMap.set(RequestEvShareQData, qData);
|
|
1183
|
-
} finally {
|
|
1184
|
-
await stream.ready;
|
|
1185
|
-
await stream.close();
|
|
1186
|
-
await pipe;
|
|
1187
|
-
}
|
|
1188
|
-
await writableStream.close();
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
async function handleQDataRedirect(requestEv) {
|
|
1192
|
-
try {
|
|
1193
|
-
await requestEv.next();
|
|
1194
|
-
} catch (err) {
|
|
1195
|
-
if (!(err instanceof requestHandler$1.RedirectMessage)) {
|
|
1196
|
-
throw err;
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
if (requestEv.headersSent) {
|
|
1200
|
-
return;
|
|
1201
|
-
}
|
|
1202
|
-
const status = requestEv.status();
|
|
1203
|
-
const location = requestEv.headers.get("Location");
|
|
1204
|
-
const isRedirect = status >= 301 && status <= 308 && location;
|
|
1205
|
-
if (isRedirect) {
|
|
1206
|
-
const adaptedLocation = makeQDataPath(location);
|
|
1207
|
-
if (adaptedLocation) {
|
|
1208
|
-
requestEv.headers.set("Location", adaptedLocation);
|
|
1209
|
-
requestEv.getWritableStream().close();
|
|
1210
|
-
return;
|
|
1211
|
-
} else {
|
|
1212
|
-
requestEv.status(200);
|
|
1213
|
-
requestEv.headers.delete("Location");
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
async function renderQData(requestEv) {
|
|
1218
|
-
await requestEv.next();
|
|
1219
|
-
if (requestEv.headersSent || requestEv.exited) {
|
|
1220
|
-
return;
|
|
1221
|
-
}
|
|
1222
|
-
const status = requestEv.status();
|
|
1223
|
-
const redirectLocation = requestEv.headers.get("Location");
|
|
1224
|
-
requestEv.request.headers.forEach((value, key) => value);
|
|
1225
|
-
requestEv.headers.set("Content-Type", "application/json; charset=utf-8");
|
|
1226
|
-
let loaders = getRequestLoaders(requestEv);
|
|
1227
|
-
const selectedLoaderIds = requestEv.query.getAll(routing.QLOADER_KEY);
|
|
1228
|
-
const hasCustomLoaders = selectedLoaderIds.length > 0;
|
|
1229
|
-
if (hasCustomLoaders) {
|
|
1230
|
-
const selectedLoaders = {};
|
|
1231
|
-
for (const loaderId of selectedLoaderIds) {
|
|
1232
|
-
const loader = loaders[loaderId];
|
|
1233
|
-
selectedLoaders[loaderId] = loader;
|
|
1234
|
-
}
|
|
1235
|
-
loaders = selectedLoaders;
|
|
1236
|
-
}
|
|
1237
|
-
const qData = hasCustomLoaders ? {
|
|
1238
|
-
// send minimal data to the client
|
|
1239
|
-
loaders,
|
|
1240
|
-
status: status !== 200 ? status : 200,
|
|
1241
|
-
href: getPathname(requestEv.url)
|
|
1242
|
-
} : {
|
|
1243
|
-
loaders,
|
|
1244
|
-
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1245
|
-
status: status !== 200 ? status : 200,
|
|
1246
|
-
href: getPathname(requestEv.url),
|
|
1247
|
-
redirect: redirectLocation ?? void 0,
|
|
1248
|
-
isRewrite: requestEv.sharedMap.get(RequestEvIsRewrite)
|
|
1249
|
-
};
|
|
1250
|
-
const writer = requestEv.getWritableStream().getWriter();
|
|
1251
|
-
const data = await internal._serialize([qData]);
|
|
1252
|
-
writer.write(encoder.encode(data));
|
|
1253
|
-
requestEv.sharedMap.set(RequestEvShareQData, qData);
|
|
1254
|
-
writer.close();
|
|
1255
|
-
}
|
|
1256
|
-
function makeQDataPath(href) {
|
|
1257
|
-
if (href.startsWith("/")) {
|
|
1258
|
-
if (!href.includes(QDATA_JSON)) {
|
|
1259
|
-
const url = new URL(href, "http://localhost");
|
|
1260
|
-
const pathname = url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname;
|
|
1261
|
-
return pathname + QDATA_JSON + url.search;
|
|
1262
|
-
}
|
|
1263
|
-
return href;
|
|
1264
|
-
} else {
|
|
1265
|
-
return void 0;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
function now() {
|
|
1269
|
-
return typeof performance !== "undefined" ? performance.now() : 0;
|
|
1270
|
-
}
|
|
1271
|
-
async function measure(requestEv, name, fn) {
|
|
1272
|
-
const start = now();
|
|
1273
|
-
try {
|
|
1274
|
-
return await fn();
|
|
1275
|
-
} finally {
|
|
1276
|
-
const duration = now() - start;
|
|
1277
|
-
let measurements = requestEv.sharedMap.get(RequestEvShareServerTiming);
|
|
1278
|
-
if (!measurements) {
|
|
1279
|
-
requestEv.sharedMap.set(RequestEvShareServerTiming, measurements = []);
|
|
1280
|
-
}
|
|
1281
|
-
measurements.push([name, duration]);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
function isContentType(headers, ...types2) {
|
|
1285
|
-
const type = headers.get("content-type")?.split(/;/, 1)[0].trim() ?? "";
|
|
1286
|
-
return types2.includes(type);
|
|
1287
|
-
}
|
|
1288
|
-
exports._asyncRequestStore = void 0;
|
|
1289
|
-
if (build.isServer) {
|
|
1290
|
-
import("node:async_hooks").then((module2) => {
|
|
1291
|
-
exports._asyncRequestStore = new module2.AsyncLocalStorage();
|
|
1292
|
-
}).catch((err) => {
|
|
1293
|
-
console.warn(
|
|
1294
|
-
"\n=====================\n Qwik Router Warning:\n AsyncLocalStorage is not available, continuing without it.\n This impacts concurrent async server calls, where they lose access to the ServerRequestEv object.\n=====================\n\n",
|
|
1295
|
-
err
|
|
1296
|
-
);
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
let qwikRouterConfigActual;
|
|
1300
|
-
async function requestHandler(serverRequestEv, opts) {
|
|
1301
|
-
const { render, checkOrigin } = opts;
|
|
1302
|
-
let { qwikRouterConfig } = opts;
|
|
1303
|
-
if (!qwikRouterConfig) {
|
|
1304
|
-
if (!qwikRouterConfigActual) {
|
|
1305
|
-
qwikRouterConfigActual = await import("@qwik-router-config");
|
|
1306
|
-
}
|
|
1307
|
-
qwikRouterConfig = qwikRouterConfigActual;
|
|
1308
|
-
}
|
|
1309
|
-
if (!qwikRouterConfig) {
|
|
1310
|
-
throw new Error("qwikRouterConfig is required.");
|
|
1311
|
-
}
|
|
1312
|
-
const { pathname, isInternal } = getRouteMatchPathname(serverRequestEv.url.pathname);
|
|
1313
|
-
const routeAndHandlers = await loadRequestHandlers(
|
|
1314
|
-
qwikRouterConfig,
|
|
1315
|
-
pathname,
|
|
1316
|
-
serverRequestEv.request.method,
|
|
1317
|
-
checkOrigin ?? true,
|
|
1318
|
-
render,
|
|
1319
|
-
isInternal
|
|
1320
|
-
);
|
|
1321
|
-
if (routeAndHandlers) {
|
|
1322
|
-
const [route, requestHandlers] = routeAndHandlers;
|
|
1323
|
-
const rebuildRouteInfo = async (url) => {
|
|
1324
|
-
const { pathname: pathname2 } = getRouteMatchPathname(url.pathname);
|
|
1325
|
-
const routeAndHandlers2 = await loadRequestHandlers(
|
|
1326
|
-
qwikRouterConfig,
|
|
1327
|
-
pathname2,
|
|
1328
|
-
serverRequestEv.request.method,
|
|
1329
|
-
checkOrigin ?? true,
|
|
1330
|
-
render,
|
|
1331
|
-
isInternal
|
|
1332
|
-
);
|
|
1333
|
-
if (routeAndHandlers2) {
|
|
1334
|
-
const [loadedRoute, requestHandlers2] = routeAndHandlers2;
|
|
1335
|
-
return { loadedRoute, requestHandlers: requestHandlers2 };
|
|
1336
|
-
} else {
|
|
1337
|
-
return { loadedRoute: null, requestHandlers: [] };
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
return runQwikRouter(
|
|
1341
|
-
serverRequestEv,
|
|
1342
|
-
route,
|
|
1343
|
-
requestHandlers,
|
|
1344
|
-
rebuildRouteInfo,
|
|
1345
|
-
qwikRouterConfig.basePathname
|
|
1346
|
-
);
|
|
1347
|
-
}
|
|
1348
|
-
return null;
|
|
1349
|
-
}
|
|
1350
|
-
async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrigin, renderFn, isInternal) {
|
|
1351
|
-
const { routes, serverPlugins, menus, cacheModules } = qwikRouterConfig;
|
|
1352
|
-
const route = await routing.loadRoute(routes, menus, cacheModules, pathname, isInternal);
|
|
1353
|
-
const requestHandlers = resolveRequestHandlers(
|
|
1354
|
-
serverPlugins,
|
|
1355
|
-
route,
|
|
1356
|
-
method,
|
|
1357
|
-
checkOrigin,
|
|
1358
|
-
renderQwikMiddleware(renderFn),
|
|
1359
|
-
isInternal
|
|
1360
|
-
);
|
|
1361
|
-
if (requestHandlers.length > 0) {
|
|
1362
|
-
return [route, requestHandlers];
|
|
1363
|
-
}
|
|
1364
|
-
return null;
|
|
1365
|
-
}
|
|
1366
|
-
const notFounds = [
|
|
1367
|
-
// Will be replaced in post-build with the 404s generated by SSG
|
|
1368
|
-
"__QWIK_ROUTER_NOT_FOUND_ARRAY__"
|
|
1369
|
-
];
|
|
1370
|
-
function getNotFound(prefix) {
|
|
1371
|
-
for (const [path, html] of notFounds) {
|
|
1372
|
-
if (prefix.startsWith(path)) {
|
|
1373
|
-
return html;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
return errorHandler.minimalHtmlResponse(404, "Resource Not Found");
|
|
1377
|
-
}
|
|
1378
|
-
const staticPaths = /* @__PURE__ */ new Set(["__QWIK_ROUTER_STATIC_PATHS_ARRAY__"]);
|
|
1379
|
-
function isStaticPath(method, url) {
|
|
1380
|
-
if (method.toUpperCase() !== "GET") {
|
|
1381
|
-
return false;
|
|
1382
|
-
}
|
|
1383
|
-
const p = url.pathname;
|
|
1384
|
-
if (p.startsWith("/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/")) {
|
|
1385
|
-
return true;
|
|
1386
|
-
}
|
|
1387
|
-
if (p.startsWith("/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/")) {
|
|
1388
|
-
return true;
|
|
1389
|
-
}
|
|
1390
|
-
if (staticPaths.has(p)) {
|
|
1391
|
-
return true;
|
|
1392
|
-
}
|
|
1393
|
-
if (p.endsWith("/q-data.json")) {
|
|
1394
|
-
const pWithoutQdata = p.replace(/\/q-data.json$/, "");
|
|
1395
|
-
if (staticPaths.has(pWithoutQdata + "/")) {
|
|
1396
|
-
return true;
|
|
1397
|
-
}
|
|
1398
|
-
if (staticPaths.has(pWithoutQdata)) {
|
|
1399
|
-
return true;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
return false;
|
|
1403
|
-
}
|
|
1404
|
-
class ServerError extends Error {
|
|
1405
|
-
constructor(status, data) {
|
|
1406
|
-
super(typeof data === "string" ? data : void 0);
|
|
1407
|
-
this.status = status;
|
|
1408
|
-
this.data = data;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
class AbortMessage {
|
|
1412
|
-
}
|
|
1413
|
-
class RedirectMessage extends AbortMessage {
|
|
1414
|
-
}
|
|
1415
|
-
class RewriteMessage extends AbortMessage {
|
|
1416
|
-
constructor(pathname) {
|
|
1417
|
-
super();
|
|
1418
|
-
this.pathname = pathname;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
class _TextEncoderStream_polyfill {
|
|
1422
|
-
constructor() {
|
|
1423
|
-
__privateAdd(this, _pendingHighSurrogate, null);
|
|
1424
|
-
__privateAdd(this, _handle, new TextEncoder());
|
|
1425
|
-
__privateAdd(this, _transform, new TransformStream({
|
|
1426
|
-
transform: (chunk, controller) => {
|
|
1427
|
-
chunk = String(chunk);
|
|
1428
|
-
let finalChunk = "";
|
|
1429
|
-
for (let i = 0; i < chunk.length; i++) {
|
|
1430
|
-
const item = chunk[i];
|
|
1431
|
-
const codeUnit = item.charCodeAt(0);
|
|
1432
|
-
if (__privateGet(this, _pendingHighSurrogate) !== null) {
|
|
1433
|
-
const highSurrogate = __privateGet(this, _pendingHighSurrogate);
|
|
1434
|
-
__privateSet(this, _pendingHighSurrogate, null);
|
|
1435
|
-
if (56320 <= codeUnit && codeUnit <= 57343) {
|
|
1436
|
-
finalChunk += highSurrogate + item;
|
|
1437
|
-
continue;
|
|
1438
|
-
}
|
|
1439
|
-
finalChunk += "�";
|
|
1440
|
-
}
|
|
1441
|
-
if (55296 <= codeUnit && codeUnit <= 56319) {
|
|
1442
|
-
__privateSet(this, _pendingHighSurrogate, item);
|
|
1443
|
-
continue;
|
|
1444
|
-
}
|
|
1445
|
-
if (56320 <= codeUnit && codeUnit <= 57343) {
|
|
1446
|
-
finalChunk += "�";
|
|
1447
|
-
continue;
|
|
1448
|
-
}
|
|
1449
|
-
finalChunk += item;
|
|
1450
|
-
}
|
|
1451
|
-
if (finalChunk) {
|
|
1452
|
-
controller.enqueue(__privateGet(this, _handle).encode(finalChunk));
|
|
1453
|
-
}
|
|
1454
|
-
},
|
|
1455
|
-
flush: (controller) => {
|
|
1456
|
-
if (__privateGet(this, _pendingHighSurrogate) !== null) {
|
|
1457
|
-
controller.enqueue(new Uint8Array([239, 191, 189]));
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
}));
|
|
1461
|
-
}
|
|
1462
|
-
get encoding() {
|
|
1463
|
-
return __privateGet(this, _handle).encoding;
|
|
1464
|
-
}
|
|
1465
|
-
get readable() {
|
|
1466
|
-
return __privateGet(this, _transform).readable;
|
|
1467
|
-
}
|
|
1468
|
-
get writable() {
|
|
1469
|
-
return __privateGet(this, _transform).writable;
|
|
1470
|
-
}
|
|
1471
|
-
get [Symbol.toStringTag]() {
|
|
1472
|
-
return "TextEncoderStream";
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
_pendingHighSurrogate = new WeakMap();
|
|
1476
|
-
_handle = new WeakMap();
|
|
1477
|
-
_transform = new WeakMap();
|
|
1478
|
-
exports.getErrorHtml = errorHandler.getErrorHtml;
|
|
1479
|
-
exports.AbortMessage = AbortMessage;
|
|
1480
|
-
exports.RedirectMessage = RedirectMessage;
|
|
1481
|
-
exports.RequestEvShareQData = RequestEvShareQData;
|
|
1482
|
-
exports.RewriteMessage = RewriteMessage;
|
|
1483
|
-
exports.ServerError = ServerError;
|
|
1484
|
-
exports._TextEncoderStream_polyfill = _TextEncoderStream_polyfill;
|
|
1485
|
-
exports.getNotFound = getNotFound;
|
|
1486
|
-
exports.isStaticPath = isStaticPath;
|
|
1487
|
-
exports.mergeHeadersCookies = mergeHeadersCookies;
|
|
1488
|
-
exports.requestHandler = requestHandler;
|