@qwik.dev/router 2.0.0-beta.4 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapters/static/vite.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.cjs +1 -0
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +1 -0
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/shared/vite/index.cjs +88 -128
- package/lib/adapters/shared/vite/index.d.ts +9 -15
- package/lib/adapters/shared/vite/index.mjs +88 -124
- package/lib/adapters/{static → ssg}/vite/index.cjs +95 -124
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/{static → ssg}/vite/index.mjs +93 -123
- package/lib/adapters/vercel-edge/vite/index.d.ts +2 -2
- package/lib/index.qwik.cjs +9 -11
- package/lib/index.qwik.mjs +10 -12
- package/lib/middleware/aws-lambda/index.d.ts +3 -2
- package/lib/middleware/aws-lambda/index.mjs +2 -4
- package/lib/middleware/azure-swa/index.mjs +6 -6
- package/lib/middleware/bun/index.mjs +4 -6
- package/lib/middleware/cloudflare-pages/index.mjs +4 -6
- package/lib/middleware/deno/index.mjs +8 -7
- package/lib/middleware/firebase/index.mjs +1 -3
- package/lib/middleware/netlify-edge/index.mjs +7 -6
- package/lib/middleware/node/index.cjs +4 -8
- package/lib/middleware/node/index.mjs +7 -7
- package/lib/middleware/request-handler/index.cjs +343 -268
- package/lib/middleware/request-handler/index.d.ts +19 -7
- package/lib/middleware/request-handler/index.mjs +347 -264
- package/lib/middleware/vercel-edge/index.mjs +7 -6
- package/lib/modules.d.ts +4 -12
- package/lib/{static → ssg}/deno.mjs +1 -1
- package/lib/{static → ssg}/index.cjs +1 -1
- package/lib/{static → ssg}/index.d.ts +17 -17
- package/lib/{static → ssg}/index.mjs +1 -1
- package/lib/{static → ssg}/node.cjs +16 -16
- package/lib/{static → ssg}/node.mjs +15 -15
- package/lib/vite/index.cjs +10264 -10429
- package/lib/vite/index.mjs +5871 -6026
- package/modules.d.ts +4 -12
- package/package.json +19 -8
- package/ssg.d.ts +2 -0
- package/static.d.ts +1 -1
- package/lib/adapters/static/vite/index.d.ts +0 -10
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -1,231 +1,3 @@
|
|
|
1
|
-
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
2
|
-
var ServerError = class extends Error {
|
|
3
|
-
constructor(status, data) {
|
|
4
|
-
super(typeof data === "string" ? data : void 0);
|
|
5
|
-
this.status = status;
|
|
6
|
-
this.data = data;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
function getErrorHtml(status, e) {
|
|
10
|
-
let message = "Server Error";
|
|
11
|
-
if (e != null) {
|
|
12
|
-
if (typeof e.message === "string") {
|
|
13
|
-
message = e.message;
|
|
14
|
-
} else {
|
|
15
|
-
message = String(e);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
|
|
19
|
-
}
|
|
20
|
-
function minimalHtmlResponse(status, message) {
|
|
21
|
-
if (typeof status !== "number") {
|
|
22
|
-
status = 500;
|
|
23
|
-
}
|
|
24
|
-
if (typeof message === "string") {
|
|
25
|
-
message = escapeHtml(message);
|
|
26
|
-
} else {
|
|
27
|
-
message = "";
|
|
28
|
-
}
|
|
29
|
-
const width = typeof message === "string" ? "600px" : "300px";
|
|
30
|
-
const color = status >= 500 ? COLOR_500 : COLOR_400;
|
|
31
|
-
return `
|
|
32
|
-
<head>
|
|
33
|
-
<meta charset="utf-8">
|
|
34
|
-
<meta http-equiv="Status" content="${status}">
|
|
35
|
-
<title>${status} ${message}</title>
|
|
36
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
37
|
-
<style>
|
|
38
|
-
body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
|
|
39
|
-
p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
|
|
40
|
-
strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
|
|
41
|
-
span { display: inline-block; padding: 15px; }
|
|
42
|
-
</style>
|
|
43
|
-
</head>
|
|
44
|
-
<body><p><strong>${status}</strong> <span>${message}</span></p></body>
|
|
45
|
-
`;
|
|
46
|
-
}
|
|
47
|
-
var ESCAPE_HTML = /[&<>]/g;
|
|
48
|
-
var escapeHtml = (s) => {
|
|
49
|
-
return s.replace(ESCAPE_HTML, (c) => {
|
|
50
|
-
switch (c) {
|
|
51
|
-
case "&":
|
|
52
|
-
return "&";
|
|
53
|
-
case "<":
|
|
54
|
-
return "<";
|
|
55
|
-
case ">":
|
|
56
|
-
return ">";
|
|
57
|
-
default:
|
|
58
|
-
return "";
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
var COLOR_400 = "#006ce9";
|
|
63
|
-
var COLOR_500 = "#713fc2";
|
|
64
|
-
|
|
65
|
-
// packages/qwik-router/src/middleware/request-handler/cookie.ts
|
|
66
|
-
var SAMESITE = {
|
|
67
|
-
lax: "Lax",
|
|
68
|
-
Lax: "Lax",
|
|
69
|
-
None: "None",
|
|
70
|
-
none: "None",
|
|
71
|
-
strict: "Strict",
|
|
72
|
-
Strict: "Strict"
|
|
73
|
-
};
|
|
74
|
-
var UNIT = {
|
|
75
|
-
seconds: 1,
|
|
76
|
-
minutes: 1 * 60,
|
|
77
|
-
hours: 1 * 60 * 60,
|
|
78
|
-
days: 1 * 60 * 60 * 24,
|
|
79
|
-
weeks: 1 * 60 * 60 * 24 * 7
|
|
80
|
-
};
|
|
81
|
-
var createSetCookieValue = (cookieName, cookieValue, options) => {
|
|
82
|
-
const c = [`${cookieName}=${cookieValue}`];
|
|
83
|
-
if (typeof options.domain === "string") {
|
|
84
|
-
c.push(`Domain=${options.domain}`);
|
|
85
|
-
}
|
|
86
|
-
if (typeof options.maxAge === "number") {
|
|
87
|
-
c.push(`Max-Age=${options.maxAge}`);
|
|
88
|
-
} else if (Array.isArray(options.maxAge)) {
|
|
89
|
-
c.push(`Max-Age=${options.maxAge[0] * UNIT[options.maxAge[1]]}`);
|
|
90
|
-
} else if (typeof options.expires === "number" || typeof options.expires == "string") {
|
|
91
|
-
c.push(`Expires=${options.expires}`);
|
|
92
|
-
} else if (options.expires instanceof Date) {
|
|
93
|
-
c.push(`Expires=${options.expires.toUTCString()}`);
|
|
94
|
-
}
|
|
95
|
-
if (options.httpOnly) {
|
|
96
|
-
c.push("HttpOnly");
|
|
97
|
-
}
|
|
98
|
-
if (typeof options.path === "string") {
|
|
99
|
-
c.push(`Path=${options.path}`);
|
|
100
|
-
}
|
|
101
|
-
const sameSite = resolveSameSite(options.sameSite);
|
|
102
|
-
if (sameSite) {
|
|
103
|
-
c.push(`SameSite=${sameSite}`);
|
|
104
|
-
}
|
|
105
|
-
if (options.secure) {
|
|
106
|
-
c.push("Secure");
|
|
107
|
-
}
|
|
108
|
-
return c.join("; ");
|
|
109
|
-
};
|
|
110
|
-
function tryDecodeUriComponent(str) {
|
|
111
|
-
try {
|
|
112
|
-
return decodeURIComponent(str);
|
|
113
|
-
} catch {
|
|
114
|
-
return str;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
var parseCookieString = (cookieString) => {
|
|
118
|
-
const cookie = {};
|
|
119
|
-
if (typeof cookieString === "string" && cookieString !== "") {
|
|
120
|
-
const cookieSegments = cookieString.split(";");
|
|
121
|
-
for (const cookieSegment of cookieSegments) {
|
|
122
|
-
const separatorIndex = cookieSegment.indexOf("=");
|
|
123
|
-
if (separatorIndex !== -1) {
|
|
124
|
-
cookie[tryDecodeUriComponent(cookieSegment.slice(0, separatorIndex).trim())] = tryDecodeUriComponent(cookieSegment.slice(separatorIndex + 1).trim());
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return cookie;
|
|
129
|
-
};
|
|
130
|
-
function resolveSameSite(sameSite) {
|
|
131
|
-
if (sameSite === true) {
|
|
132
|
-
return "Strict";
|
|
133
|
-
}
|
|
134
|
-
if (sameSite === false) {
|
|
135
|
-
return "None";
|
|
136
|
-
}
|
|
137
|
-
if (sameSite) {
|
|
138
|
-
return SAMESITE[sameSite];
|
|
139
|
-
}
|
|
140
|
-
return void 0;
|
|
141
|
-
}
|
|
142
|
-
var REQ_COOKIE = Symbol("request-cookies");
|
|
143
|
-
var RES_COOKIE = Symbol("response-cookies");
|
|
144
|
-
var LIVE_COOKIE = Symbol("live-cookies");
|
|
145
|
-
var Cookie = class {
|
|
146
|
-
[REQ_COOKIE];
|
|
147
|
-
[RES_COOKIE] = {};
|
|
148
|
-
[LIVE_COOKIE] = {};
|
|
149
|
-
appendCounter = 0;
|
|
150
|
-
constructor(cookieString) {
|
|
151
|
-
this[REQ_COOKIE] = parseCookieString(cookieString);
|
|
152
|
-
this[LIVE_COOKIE] = { ...this[REQ_COOKIE] };
|
|
153
|
-
}
|
|
154
|
-
get(cookieName, live = true) {
|
|
155
|
-
const value = this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
156
|
-
if (!value) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
value,
|
|
161
|
-
json() {
|
|
162
|
-
return JSON.parse(value);
|
|
163
|
-
},
|
|
164
|
-
number() {
|
|
165
|
-
return Number(value);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
getAll(live = true) {
|
|
170
|
-
return Object.keys(this[live ? LIVE_COOKIE : REQ_COOKIE]).reduce(
|
|
171
|
-
(cookies, cookieName) => {
|
|
172
|
-
cookies[cookieName] = this.get(cookieName);
|
|
173
|
-
return cookies;
|
|
174
|
-
},
|
|
175
|
-
{}
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
has(cookieName, live = true) {
|
|
179
|
-
return !!this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
180
|
-
}
|
|
181
|
-
set(cookieName, cookieValue, options = {}) {
|
|
182
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
183
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
184
|
-
this[RES_COOKIE][cookieName] = createSetCookieValue(cookieName, resolvedValue, options);
|
|
185
|
-
}
|
|
186
|
-
append(cookieName, cookieValue, options = {}) {
|
|
187
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
188
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
189
|
-
this[RES_COOKIE][++this.appendCounter] = createSetCookieValue(
|
|
190
|
-
cookieName,
|
|
191
|
-
resolvedValue,
|
|
192
|
-
options
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
delete(name, options) {
|
|
196
|
-
this.set(name, "deleted", { ...options, maxAge: 0 });
|
|
197
|
-
this[LIVE_COOKIE][name] = null;
|
|
198
|
-
}
|
|
199
|
-
headers() {
|
|
200
|
-
return Object.values(this[RES_COOKIE]);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var mergeHeadersCookies = (headers, cookies) => {
|
|
204
|
-
const cookieHeaders = cookies.headers();
|
|
205
|
-
if (cookieHeaders.length > 0) {
|
|
206
|
-
const newHeaders = new Headers(headers);
|
|
207
|
-
for (const cookie of cookieHeaders) {
|
|
208
|
-
newHeaders.append("Set-Cookie", cookie);
|
|
209
|
-
}
|
|
210
|
-
return newHeaders;
|
|
211
|
-
}
|
|
212
|
-
return headers;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// packages/qwik-router/src/middleware/request-handler/redirect-handler.ts
|
|
216
|
-
var AbortMessage = class {
|
|
217
|
-
};
|
|
218
|
-
var RedirectMessage = class extends AbortMessage {
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// packages/qwik-router/src/middleware/request-handler/rewrite-handler.ts
|
|
222
|
-
var RewriteMessage = class extends AbortMessage {
|
|
223
|
-
constructor(pathname) {
|
|
224
|
-
super();
|
|
225
|
-
this.pathname = pathname;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
1
|
// packages/qwik-router/src/runtime/src/constants.ts
|
|
230
2
|
var MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
231
3
|
var QACTION_KEY = "qaction";
|
|
@@ -457,6 +229,12 @@ var getMenuLoader = (menus, pathname) => {
|
|
|
457
229
|
}
|
|
458
230
|
};
|
|
459
231
|
|
|
232
|
+
// packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts
|
|
233
|
+
import { _UNINITIALIZED as _UNINITIALIZED3 } from "@qwik.dev/core/internal";
|
|
234
|
+
|
|
235
|
+
// packages/qwik-router/src/middleware/request-handler/request-event.ts
|
|
236
|
+
import { _UNINITIALIZED as _UNINITIALIZED2 } from "@qwik.dev/core/internal";
|
|
237
|
+
|
|
460
238
|
// packages/qwik-router/src/middleware/request-handler/cache-control.ts
|
|
461
239
|
function createCacheControl(cacheControl) {
|
|
462
240
|
const controls = [];
|
|
@@ -520,7 +298,228 @@ function createCacheControl(cacheControl) {
|
|
|
520
298
|
return controls.join(", ");
|
|
521
299
|
}
|
|
522
300
|
|
|
301
|
+
// packages/qwik-router/src/middleware/request-handler/cookie.ts
|
|
302
|
+
var SAMESITE = {
|
|
303
|
+
lax: "Lax",
|
|
304
|
+
Lax: "Lax",
|
|
305
|
+
None: "None",
|
|
306
|
+
none: "None",
|
|
307
|
+
strict: "Strict",
|
|
308
|
+
Strict: "Strict"
|
|
309
|
+
};
|
|
310
|
+
var UNIT = {
|
|
311
|
+
seconds: 1,
|
|
312
|
+
minutes: 1 * 60,
|
|
313
|
+
hours: 1 * 60 * 60,
|
|
314
|
+
days: 1 * 60 * 60 * 24,
|
|
315
|
+
weeks: 1 * 60 * 60 * 24 * 7
|
|
316
|
+
};
|
|
317
|
+
var createSetCookieValue = (cookieName, cookieValue, options) => {
|
|
318
|
+
const c = [`${cookieName}=${cookieValue}`];
|
|
319
|
+
if (typeof options.domain === "string") {
|
|
320
|
+
c.push(`Domain=${options.domain}`);
|
|
321
|
+
}
|
|
322
|
+
if (typeof options.maxAge === "number") {
|
|
323
|
+
c.push(`Max-Age=${options.maxAge}`);
|
|
324
|
+
} else if (Array.isArray(options.maxAge)) {
|
|
325
|
+
c.push(`Max-Age=${options.maxAge[0] * UNIT[options.maxAge[1]]}`);
|
|
326
|
+
} else if (typeof options.expires === "number" || typeof options.expires == "string") {
|
|
327
|
+
c.push(`Expires=${options.expires}`);
|
|
328
|
+
} else if (options.expires instanceof Date) {
|
|
329
|
+
c.push(`Expires=${options.expires.toUTCString()}`);
|
|
330
|
+
}
|
|
331
|
+
if (options.httpOnly) {
|
|
332
|
+
c.push("HttpOnly");
|
|
333
|
+
}
|
|
334
|
+
if (typeof options.path === "string") {
|
|
335
|
+
c.push(`Path=${options.path}`);
|
|
336
|
+
}
|
|
337
|
+
const sameSite = resolveSameSite(options.sameSite);
|
|
338
|
+
if (sameSite) {
|
|
339
|
+
c.push(`SameSite=${sameSite}`);
|
|
340
|
+
}
|
|
341
|
+
if (options.secure) {
|
|
342
|
+
c.push("Secure");
|
|
343
|
+
}
|
|
344
|
+
return c.join("; ");
|
|
345
|
+
};
|
|
346
|
+
function tryDecodeUriComponent(str) {
|
|
347
|
+
try {
|
|
348
|
+
return decodeURIComponent(str);
|
|
349
|
+
} catch {
|
|
350
|
+
return str;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
var parseCookieString = (cookieString) => {
|
|
354
|
+
const cookie = {};
|
|
355
|
+
if (typeof cookieString === "string" && cookieString !== "") {
|
|
356
|
+
const cookieSegments = cookieString.split(";");
|
|
357
|
+
for (const cookieSegment of cookieSegments) {
|
|
358
|
+
const separatorIndex = cookieSegment.indexOf("=");
|
|
359
|
+
if (separatorIndex !== -1) {
|
|
360
|
+
cookie[tryDecodeUriComponent(cookieSegment.slice(0, separatorIndex).trim())] = tryDecodeUriComponent(cookieSegment.slice(separatorIndex + 1).trim());
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return cookie;
|
|
365
|
+
};
|
|
366
|
+
function resolveSameSite(sameSite) {
|
|
367
|
+
if (sameSite === true) {
|
|
368
|
+
return "Strict";
|
|
369
|
+
}
|
|
370
|
+
if (sameSite === false) {
|
|
371
|
+
return "None";
|
|
372
|
+
}
|
|
373
|
+
if (sameSite) {
|
|
374
|
+
return SAMESITE[sameSite];
|
|
375
|
+
}
|
|
376
|
+
return void 0;
|
|
377
|
+
}
|
|
378
|
+
var REQ_COOKIE = Symbol("request-cookies");
|
|
379
|
+
var RES_COOKIE = Symbol("response-cookies");
|
|
380
|
+
var LIVE_COOKIE = Symbol("live-cookies");
|
|
381
|
+
var Cookie = class {
|
|
382
|
+
[REQ_COOKIE];
|
|
383
|
+
[RES_COOKIE] = {};
|
|
384
|
+
[LIVE_COOKIE] = {};
|
|
385
|
+
appendCounter = 0;
|
|
386
|
+
constructor(cookieString) {
|
|
387
|
+
this[REQ_COOKIE] = parseCookieString(cookieString);
|
|
388
|
+
this[LIVE_COOKIE] = { ...this[REQ_COOKIE] };
|
|
389
|
+
}
|
|
390
|
+
get(cookieName, live = true) {
|
|
391
|
+
const value = this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
392
|
+
if (!value) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
value,
|
|
397
|
+
json() {
|
|
398
|
+
return JSON.parse(value);
|
|
399
|
+
},
|
|
400
|
+
number() {
|
|
401
|
+
return Number(value);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
getAll(live = true) {
|
|
406
|
+
return Object.keys(this[live ? LIVE_COOKIE : REQ_COOKIE]).reduce(
|
|
407
|
+
(cookies, cookieName) => {
|
|
408
|
+
cookies[cookieName] = this.get(cookieName);
|
|
409
|
+
return cookies;
|
|
410
|
+
},
|
|
411
|
+
{}
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
has(cookieName, live = true) {
|
|
415
|
+
return !!this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
416
|
+
}
|
|
417
|
+
set(cookieName, cookieValue, options = {}) {
|
|
418
|
+
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
419
|
+
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
420
|
+
this[RES_COOKIE][cookieName] = createSetCookieValue(cookieName, resolvedValue, options);
|
|
421
|
+
}
|
|
422
|
+
append(cookieName, cookieValue, options = {}) {
|
|
423
|
+
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
424
|
+
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
425
|
+
this[RES_COOKIE][++this.appendCounter] = createSetCookieValue(
|
|
426
|
+
cookieName,
|
|
427
|
+
resolvedValue,
|
|
428
|
+
options
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
delete(name, options) {
|
|
432
|
+
this.set(name, "deleted", { ...options, maxAge: 0 });
|
|
433
|
+
this[LIVE_COOKIE][name] = null;
|
|
434
|
+
}
|
|
435
|
+
headers() {
|
|
436
|
+
return Object.values(this[RES_COOKIE]);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
var mergeHeadersCookies = (headers, cookies) => {
|
|
440
|
+
const cookieHeaders = cookies.headers();
|
|
441
|
+
if (cookieHeaders.length > 0) {
|
|
442
|
+
const newHeaders = new Headers(headers);
|
|
443
|
+
for (const cookie of cookieHeaders) {
|
|
444
|
+
newHeaders.append("Set-Cookie", cookie);
|
|
445
|
+
}
|
|
446
|
+
return newHeaders;
|
|
447
|
+
}
|
|
448
|
+
return headers;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// packages/qwik-router/src/middleware/request-handler/request-event.ts
|
|
452
|
+
import {
|
|
453
|
+
AbortMessage as AbortMessage2,
|
|
454
|
+
RedirectMessage as RedirectMessage2,
|
|
455
|
+
ServerError as ServerError2,
|
|
456
|
+
RewriteMessage as RewriteMessage2
|
|
457
|
+
} from "@qwik.dev/router/middleware/request-handler";
|
|
458
|
+
|
|
459
|
+
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
460
|
+
function getErrorHtml(status, e) {
|
|
461
|
+
let message = "Server Error";
|
|
462
|
+
if (e != null) {
|
|
463
|
+
if (typeof e.message === "string") {
|
|
464
|
+
message = e.message;
|
|
465
|
+
} else {
|
|
466
|
+
message = String(e);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
|
|
470
|
+
}
|
|
471
|
+
function minimalHtmlResponse(status, message) {
|
|
472
|
+
if (typeof status !== "number") {
|
|
473
|
+
status = 500;
|
|
474
|
+
}
|
|
475
|
+
if (typeof message === "string") {
|
|
476
|
+
message = escapeHtml(message);
|
|
477
|
+
} else {
|
|
478
|
+
message = "";
|
|
479
|
+
}
|
|
480
|
+
const width = typeof message === "string" ? "600px" : "300px";
|
|
481
|
+
const color = status >= 500 ? COLOR_500 : COLOR_400;
|
|
482
|
+
return `
|
|
483
|
+
<head>
|
|
484
|
+
<meta charset="utf-8">
|
|
485
|
+
<meta http-equiv="Status" content="${status}">
|
|
486
|
+
<title>${status} ${message}</title>
|
|
487
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
488
|
+
<style>
|
|
489
|
+
body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
|
|
490
|
+
p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
|
|
491
|
+
strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
|
|
492
|
+
span { display: inline-block; padding: 15px; }
|
|
493
|
+
</style>
|
|
494
|
+
</head>
|
|
495
|
+
<body><p><strong>${status}</strong> <span>${message}</span></p></body>
|
|
496
|
+
`;
|
|
497
|
+
}
|
|
498
|
+
var ESCAPE_HTML = /[&<>]/g;
|
|
499
|
+
var escapeHtml = (s) => {
|
|
500
|
+
return s.replace(ESCAPE_HTML, (c) => {
|
|
501
|
+
switch (c) {
|
|
502
|
+
case "&":
|
|
503
|
+
return "&";
|
|
504
|
+
case "<":
|
|
505
|
+
return "<";
|
|
506
|
+
case ">":
|
|
507
|
+
return ">";
|
|
508
|
+
default:
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
var COLOR_400 = "#006ce9";
|
|
514
|
+
var COLOR_500 = "#713fc2";
|
|
515
|
+
|
|
523
516
|
// packages/qwik-router/src/middleware/request-handler/user-response.ts
|
|
517
|
+
import {
|
|
518
|
+
AbortMessage,
|
|
519
|
+
RedirectMessage,
|
|
520
|
+
ServerError,
|
|
521
|
+
RewriteMessage
|
|
522
|
+
} from "@qwik.dev/router/middleware/request-handler";
|
|
524
523
|
var asyncStore;
|
|
525
524
|
import("node:async_hooks").then((module) => {
|
|
526
525
|
const AsyncLocalStorage = module.AsyncLocalStorage;
|
|
@@ -532,14 +531,13 @@ import("node:async_hooks").then((module) => {
|
|
|
532
531
|
err
|
|
533
532
|
);
|
|
534
533
|
});
|
|
535
|
-
function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo,
|
|
534
|
+
function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, basePathname = "/", qwikSerializer) {
|
|
536
535
|
let resolve;
|
|
537
536
|
const responsePromise = new Promise((r) => resolve = r);
|
|
538
537
|
const requestEv = createRequestEvent(
|
|
539
538
|
serverRequestEv,
|
|
540
539
|
loadedRoute,
|
|
541
540
|
requestHandlers,
|
|
542
|
-
trailingSlash,
|
|
543
541
|
basePathname,
|
|
544
542
|
qwikSerializer,
|
|
545
543
|
resolve
|
|
@@ -593,7 +591,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
593
591
|
const stream = requestEv.getWritableStream();
|
|
594
592
|
if (!stream.locked) {
|
|
595
593
|
const writer = stream.getWriter();
|
|
596
|
-
await writer.write(encoder.encode(
|
|
594
|
+
await writer.write(encoder.encode(getErrorHtml(500, "Internal Server Error")));
|
|
597
595
|
await writer.close();
|
|
598
596
|
}
|
|
599
597
|
} catch {
|
|
@@ -613,9 +611,9 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
613
611
|
}
|
|
614
612
|
}
|
|
615
613
|
}
|
|
616
|
-
function getRouteMatchPathname(pathname
|
|
614
|
+
function getRouteMatchPathname(pathname) {
|
|
617
615
|
if (pathname.endsWith(QDATA_JSON)) {
|
|
618
|
-
const trimEnd = pathname.length - QDATA_JSON_LEN + (
|
|
616
|
+
const trimEnd = pathname.length - QDATA_JSON_LEN + (globalThis.__NO_TRAILING_SLASH__ ? 0 : 1);
|
|
619
617
|
pathname = pathname.slice(0, trimEnd);
|
|
620
618
|
if (pathname === "") {
|
|
621
619
|
pathname = "/";
|
|
@@ -635,7 +633,6 @@ var RequestEvQwikSerializer = Symbol("RequestEvQwikSerializer");
|
|
|
635
633
|
var RequestEvLoaderSerializationStrategyMap = Symbol(
|
|
636
634
|
"RequestEvLoaderSerializationStrategyMap"
|
|
637
635
|
);
|
|
638
|
-
var RequestEvTrailingSlash = Symbol("RequestEvTrailingSlash");
|
|
639
636
|
var RequestRouteName = "@routeName";
|
|
640
637
|
var RequestEvSharedActionId = "@actionId";
|
|
641
638
|
var RequestEvSharedActionFormData = "@actionFormData";
|
|
@@ -643,7 +640,7 @@ var RequestEvSharedNonce = "@nonce";
|
|
|
643
640
|
var RequestEvIsRewrite = "@rewrite";
|
|
644
641
|
var RequestEvShareServerTiming = "@serverTiming";
|
|
645
642
|
var RequestEvShareQData = "qData";
|
|
646
|
-
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers,
|
|
643
|
+
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, basePathname, qwikSerializer, resolved) {
|
|
647
644
|
const { request, platform, env } = serverRequestEv;
|
|
648
645
|
const sharedMap = /* @__PURE__ */ new Map();
|
|
649
646
|
const cookie = new Cookie(request.headers.get("cookie"));
|
|
@@ -651,7 +648,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
651
648
|
const url = new URL(request.url);
|
|
652
649
|
if (url.pathname.endsWith(QDATA_JSON)) {
|
|
653
650
|
url.pathname = url.pathname.slice(0, -QDATA_JSON_LEN);
|
|
654
|
-
if (
|
|
651
|
+
if (!globalThis.__NO_TRAILING_SLASH__ && !url.pathname.endsWith("/")) {
|
|
655
652
|
url.pathname += "/";
|
|
656
653
|
}
|
|
657
654
|
sharedMap.set(IsQData, true);
|
|
@@ -721,14 +718,13 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
721
718
|
};
|
|
722
719
|
const exit = () => {
|
|
723
720
|
routeModuleIndex = ABORT_INDEX;
|
|
724
|
-
return new
|
|
721
|
+
return new AbortMessage2();
|
|
725
722
|
};
|
|
726
723
|
const loaders = {};
|
|
727
724
|
const requestEv = {
|
|
728
725
|
[RequestEvLoaders]: loaders,
|
|
729
726
|
[RequestEvLoaderSerializationStrategyMap]: /* @__PURE__ */ new Map(),
|
|
730
727
|
[RequestEvMode]: serverRequestEv.mode,
|
|
731
|
-
[RequestEvTrailingSlash]: trailingSlash,
|
|
732
728
|
get [RequestEvRoute]() {
|
|
733
729
|
return loadedRoute;
|
|
734
730
|
},
|
|
@@ -777,6 +773,10 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
777
773
|
"You can not get the returned data of a loader that has not been executed for this request."
|
|
778
774
|
);
|
|
779
775
|
}
|
|
776
|
+
if (loaders[id] === _UNINITIALIZED2) {
|
|
777
|
+
const isDev = getRequestMode(requestEv) === "dev";
|
|
778
|
+
await getRouteLoaderPromise(loaderOrAction, loaders, requestEv, isDev, qwikSerializer);
|
|
779
|
+
}
|
|
780
780
|
}
|
|
781
781
|
return loaders[id];
|
|
782
782
|
},
|
|
@@ -796,7 +796,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
796
796
|
},
|
|
797
797
|
error: (statusCode, message) => {
|
|
798
798
|
status = statusCode;
|
|
799
|
-
return new
|
|
799
|
+
return new ServerError2(statusCode, message);
|
|
800
800
|
},
|
|
801
801
|
redirect: (statusCode, url2) => {
|
|
802
802
|
check();
|
|
@@ -812,7 +812,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
812
812
|
headers.set("Cache-Control", "no-store");
|
|
813
813
|
}
|
|
814
814
|
exit();
|
|
815
|
-
return new
|
|
815
|
+
return new RedirectMessage2();
|
|
816
816
|
},
|
|
817
817
|
rewrite: (pathname) => {
|
|
818
818
|
check();
|
|
@@ -820,7 +820,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
820
820
|
throw new Error("Rewrite does not support absolute urls");
|
|
821
821
|
}
|
|
822
822
|
sharedMap.set(RequestEvIsRewrite, true);
|
|
823
|
-
return new
|
|
823
|
+
return new RewriteMessage2(pathname.replace(/\/+/g, "/"));
|
|
824
824
|
},
|
|
825
825
|
defer: (returnData) => {
|
|
826
826
|
return typeof returnData === "function" ? returnData : () => returnData;
|
|
@@ -885,9 +885,6 @@ function getRequestLoaders(requestEv) {
|
|
|
885
885
|
function getRequestLoaderSerializationStrategyMap(requestEv) {
|
|
886
886
|
return requestEv[RequestEvLoaderSerializationStrategyMap];
|
|
887
887
|
}
|
|
888
|
-
function getRequestTrailingSlash(requestEv) {
|
|
889
|
-
return requestEv[RequestEvTrailingSlash];
|
|
890
|
-
}
|
|
891
888
|
function getRequestRoute(requestEv) {
|
|
892
889
|
return requestEv[RequestEvRoute];
|
|
893
890
|
}
|
|
@@ -984,6 +981,7 @@ function getQwikRouterServerData(requestEv) {
|
|
|
984
981
|
}
|
|
985
982
|
|
|
986
983
|
// packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts
|
|
984
|
+
import { RedirectMessage as RedirectMessage3, ServerError as ServerError3 } from "@qwik.dev/router/middleware/request-handler";
|
|
987
985
|
var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderHandler) => {
|
|
988
986
|
const routeLoaders = [];
|
|
989
987
|
const routeActions = [];
|
|
@@ -1003,6 +1001,9 @@ var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderH
|
|
|
1003
1001
|
const routeName = route[0 /* RouteName */];
|
|
1004
1002
|
if (checkOrigin && (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE")) {
|
|
1005
1003
|
requestHandlers.unshift(csrfCheckMiddleware);
|
|
1004
|
+
if (checkOrigin === "lax-proto") {
|
|
1005
|
+
requestHandlers.push(csrfLaxProtoCheckMiddleware);
|
|
1006
|
+
}
|
|
1006
1007
|
}
|
|
1007
1008
|
if (isPageRoute) {
|
|
1008
1009
|
if (method === "POST" || method === "GET") {
|
|
@@ -1155,6 +1156,8 @@ function loadersMiddleware(routeLoaders) {
|
|
|
1155
1156
|
for (const loader of routeLoaders) {
|
|
1156
1157
|
if (selectedLoaderIds.includes(loader.__id)) {
|
|
1157
1158
|
currentLoaders.push(loader);
|
|
1159
|
+
} else {
|
|
1160
|
+
loaders[loader.__id] = _UNINITIALIZED3;
|
|
1158
1161
|
}
|
|
1159
1162
|
}
|
|
1160
1163
|
} else {
|
|
@@ -1254,7 +1257,7 @@ async function pureServerFunction(ev) {
|
|
|
1254
1257
|
result = await qrl.apply(ev, args);
|
|
1255
1258
|
}
|
|
1256
1259
|
} catch (err) {
|
|
1257
|
-
if (err instanceof
|
|
1260
|
+
if (err instanceof ServerError3) {
|
|
1258
1261
|
throw ev.error(err.status, err.data);
|
|
1259
1262
|
}
|
|
1260
1263
|
throw ev.error(500, "Invalid request");
|
|
@@ -1288,12 +1291,11 @@ async function pureServerFunction(ev) {
|
|
|
1288
1291
|
}
|
|
1289
1292
|
}
|
|
1290
1293
|
function fixTrailingSlash(ev) {
|
|
1291
|
-
const trailingSlash = getRequestTrailingSlash(ev);
|
|
1292
1294
|
const { basePathname, originalUrl, sharedMap } = ev;
|
|
1293
1295
|
const { pathname, search } = originalUrl;
|
|
1294
1296
|
const isQData = sharedMap.has(IsQData);
|
|
1295
1297
|
if (!isQData && pathname !== basePathname && !pathname.endsWith(".html")) {
|
|
1296
|
-
if (
|
|
1298
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1297
1299
|
if (!pathname.endsWith("/")) {
|
|
1298
1300
|
throw ev.redirect(301 /* MovedPermanently */, pathname + "/" + search);
|
|
1299
1301
|
}
|
|
@@ -1324,12 +1326,12 @@ function isLastModulePageRoute(routeModules) {
|
|
|
1324
1326
|
const lastRouteModule = routeModules[routeModules.length - 1];
|
|
1325
1327
|
return lastRouteModule && typeof lastRouteModule.default === "function";
|
|
1326
1328
|
}
|
|
1327
|
-
function getPathname(url
|
|
1329
|
+
function getPathname(url) {
|
|
1328
1330
|
url = new URL(url);
|
|
1329
1331
|
if (url.pathname.endsWith(QDATA_JSON)) {
|
|
1330
1332
|
url.pathname = url.pathname.slice(0, -QDATA_JSON.length);
|
|
1331
1333
|
}
|
|
1332
|
-
if (
|
|
1334
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1333
1335
|
if (!url.pathname.endsWith("/")) {
|
|
1334
1336
|
url.pathname += "/";
|
|
1335
1337
|
}
|
|
@@ -1342,7 +1344,13 @@ function getPathname(url, trailingSlash) {
|
|
|
1342
1344
|
return `${url.pathname}${search ? `?${search}` : ""}${url.hash}`;
|
|
1343
1345
|
}
|
|
1344
1346
|
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
1347
|
+
function csrfLaxProtoCheckMiddleware(requestEv) {
|
|
1348
|
+
checkCSRF(requestEv, "lax-proto");
|
|
1349
|
+
}
|
|
1345
1350
|
function csrfCheckMiddleware(requestEv) {
|
|
1351
|
+
checkCSRF(requestEv);
|
|
1352
|
+
}
|
|
1353
|
+
function checkCSRF(requestEv, laxProto) {
|
|
1346
1354
|
const isForm = isContentType(
|
|
1347
1355
|
requestEv.request.headers,
|
|
1348
1356
|
"application/x-www-form-urlencoded",
|
|
@@ -1352,7 +1360,10 @@ function csrfCheckMiddleware(requestEv) {
|
|
|
1352
1360
|
if (isForm) {
|
|
1353
1361
|
const inputOrigin = requestEv.request.headers.get("origin");
|
|
1354
1362
|
const origin = requestEv.url.origin;
|
|
1355
|
-
|
|
1363
|
+
let forbidden = inputOrigin !== origin;
|
|
1364
|
+
if (forbidden && laxProto && origin.startsWith("https://") && (inputOrigin == null ? void 0 : inputOrigin.slice(4)) === origin.slice(5)) {
|
|
1365
|
+
forbidden = false;
|
|
1366
|
+
}
|
|
1356
1367
|
if (forbidden) {
|
|
1357
1368
|
throw requestEv.error(
|
|
1358
1369
|
403,
|
|
@@ -1377,7 +1388,6 @@ function renderQwikMiddleware(render) {
|
|
|
1377
1388
|
if (!responseHeaders.has("Content-Type")) {
|
|
1378
1389
|
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
|
|
1379
1390
|
}
|
|
1380
|
-
const trailingSlash = getRequestTrailingSlash(requestEv);
|
|
1381
1391
|
const { readable, writable } = new TextEncoderStream();
|
|
1382
1392
|
const writableStream = requestEv.getWritableStream();
|
|
1383
1393
|
const pipe = readable.pipeTo(writableStream, { preventClose: true });
|
|
@@ -1399,7 +1409,7 @@ function renderQwikMiddleware(render) {
|
|
|
1399
1409
|
loaders: getRequestLoaders(requestEv),
|
|
1400
1410
|
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1401
1411
|
status: status !== 200 ? status : 200,
|
|
1402
|
-
href: getPathname(requestEv.url
|
|
1412
|
+
href: getPathname(requestEv.url)
|
|
1403
1413
|
};
|
|
1404
1414
|
if (typeof result.html === "string") {
|
|
1405
1415
|
await stream.write(result.html);
|
|
@@ -1421,7 +1431,7 @@ async function handleRedirect(requestEv) {
|
|
|
1421
1431
|
try {
|
|
1422
1432
|
await requestEv.next();
|
|
1423
1433
|
} catch (err) {
|
|
1424
|
-
if (!(err instanceof
|
|
1434
|
+
if (!(err instanceof RedirectMessage3)) {
|
|
1425
1435
|
throw err;
|
|
1426
1436
|
}
|
|
1427
1437
|
}
|
|
@@ -1454,7 +1464,6 @@ async function renderQData(requestEv) {
|
|
|
1454
1464
|
}
|
|
1455
1465
|
const status = requestEv.status();
|
|
1456
1466
|
const redirectLocation = requestEv.headers.get("Location");
|
|
1457
|
-
const trailingSlash = getRequestTrailingSlash(requestEv);
|
|
1458
1467
|
const requestHeaders = {};
|
|
1459
1468
|
requestEv.request.headers.forEach((value, key) => requestHeaders[key] = value);
|
|
1460
1469
|
requestEv.headers.set("Content-Type", "application/json; charset=utf-8");
|
|
@@ -1473,12 +1482,12 @@ async function renderQData(requestEv) {
|
|
|
1473
1482
|
// send minimal data to the client
|
|
1474
1483
|
loaders,
|
|
1475
1484
|
status: status !== 200 ? status : 200,
|
|
1476
|
-
href: getPathname(requestEv.url
|
|
1485
|
+
href: getPathname(requestEv.url)
|
|
1477
1486
|
} : {
|
|
1478
1487
|
loaders,
|
|
1479
1488
|
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1480
1489
|
status: status !== 200 ? status : 200,
|
|
1481
|
-
href: getPathname(requestEv.url
|
|
1490
|
+
href: getPathname(requestEv.url),
|
|
1482
1491
|
redirect: redirectLocation ?? void 0,
|
|
1483
1492
|
isRewrite: requestEv.sharedMap.get(RequestEvIsRewrite)
|
|
1484
1493
|
};
|
|
@@ -1522,13 +1531,21 @@ function isContentType(headers, ...types) {
|
|
|
1522
1531
|
}
|
|
1523
1532
|
|
|
1524
1533
|
// packages/qwik-router/src/middleware/request-handler/request-handler.ts
|
|
1534
|
+
var qwikRouterConfigActual;
|
|
1525
1535
|
async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
1526
|
-
const { render,
|
|
1536
|
+
const { render, checkOrigin } = opts;
|
|
1537
|
+
let { qwikRouterConfig } = opts;
|
|
1538
|
+
if (!qwikRouterConfig) {
|
|
1539
|
+
if (!qwikRouterConfigActual) {
|
|
1540
|
+
qwikRouterConfigActual = await import("@qwik-router-config");
|
|
1541
|
+
}
|
|
1542
|
+
qwikRouterConfig = qwikRouterConfigActual;
|
|
1543
|
+
}
|
|
1527
1544
|
if (!qwikRouterConfig) {
|
|
1528
1545
|
throw new Error("qwikRouterConfig is required.");
|
|
1529
1546
|
}
|
|
1530
1547
|
const pathname = serverRequestEv.url.pathname;
|
|
1531
|
-
const matchPathname = getRouteMatchPathname(pathname
|
|
1548
|
+
const matchPathname = getRouteMatchPathname(pathname);
|
|
1532
1549
|
const routeAndHandlers = await loadRequestHandlers(
|
|
1533
1550
|
qwikRouterConfig,
|
|
1534
1551
|
matchPathname,
|
|
@@ -1539,7 +1556,7 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
|
1539
1556
|
if (routeAndHandlers) {
|
|
1540
1557
|
const [route, requestHandlers] = routeAndHandlers;
|
|
1541
1558
|
const rebuildRouteInfo = async (url) => {
|
|
1542
|
-
const matchPathname2 = getRouteMatchPathname(url.pathname
|
|
1559
|
+
const matchPathname2 = getRouteMatchPathname(url.pathname);
|
|
1543
1560
|
const routeAndHandlers2 = await loadRequestHandlers(
|
|
1544
1561
|
qwikRouterConfig,
|
|
1545
1562
|
matchPathname2,
|
|
@@ -1559,7 +1576,6 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
|
1559
1576
|
route,
|
|
1560
1577
|
requestHandlers,
|
|
1561
1578
|
rebuildRouteInfo,
|
|
1562
|
-
qwikRouterConfig.trailingSlash,
|
|
1563
1579
|
qwikRouterConfig.basePathname,
|
|
1564
1580
|
qwikSerializer
|
|
1565
1581
|
);
|
|
@@ -1582,6 +1598,71 @@ async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrig
|
|
|
1582
1598
|
return null;
|
|
1583
1599
|
}
|
|
1584
1600
|
|
|
1601
|
+
// packages/qwik-router/src/middleware/request-handler/not-found-paths.ts
|
|
1602
|
+
var notFounds = [
|
|
1603
|
+
// Will be replaced in post-build with the 404s generated by SSG
|
|
1604
|
+
"__QWIK_ROUTER_NOT_FOUND_ARRAY__"
|
|
1605
|
+
];
|
|
1606
|
+
function getNotFound(prefix) {
|
|
1607
|
+
for (const [path, html] of notFounds) {
|
|
1608
|
+
if (prefix.startsWith(path)) {
|
|
1609
|
+
return html;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return minimalHtmlResponse(404, "Resource Not Found");
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// packages/qwik-router/src/middleware/request-handler/static-paths.ts
|
|
1616
|
+
var staticPaths = /* @__PURE__ */ new Set(["__QWIK_ROUTER_STATIC_PATHS_ARRAY__"]);
|
|
1617
|
+
function isStaticPath(method, url) {
|
|
1618
|
+
if (method.toUpperCase() !== "GET") {
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
const p = url.pathname;
|
|
1622
|
+
if (p.startsWith("/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/")) {
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
if (p.startsWith("/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/")) {
|
|
1626
|
+
return true;
|
|
1627
|
+
}
|
|
1628
|
+
if (staticPaths.has(p)) {
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
if (p.endsWith("/q-data.json")) {
|
|
1632
|
+
const pWithoutQdata = p.replace(/\/q-data.json$/, "");
|
|
1633
|
+
if (staticPaths.has(pWithoutQdata + "/")) {
|
|
1634
|
+
return true;
|
|
1635
|
+
}
|
|
1636
|
+
if (staticPaths.has(pWithoutQdata)) {
|
|
1637
|
+
return true;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// packages/qwik-router/src/middleware/request-handler/server-error.ts
|
|
1644
|
+
var ServerError4 = class extends Error {
|
|
1645
|
+
constructor(status, data) {
|
|
1646
|
+
super(typeof data === "string" ? data : void 0);
|
|
1647
|
+
this.status = status;
|
|
1648
|
+
this.data = data;
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
// packages/qwik-router/src/middleware/request-handler/redirect-handler.ts
|
|
1653
|
+
var AbortMessage3 = class {
|
|
1654
|
+
};
|
|
1655
|
+
var RedirectMessage4 = class extends AbortMessage3 {
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
// packages/qwik-router/src/middleware/request-handler/rewrite-handler.ts
|
|
1659
|
+
var RewriteMessage3 = class extends AbortMessage3 {
|
|
1660
|
+
constructor(pathname) {
|
|
1661
|
+
super();
|
|
1662
|
+
this.pathname = pathname;
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1585
1666
|
// packages/qwik-router/src/middleware/request-handler/polyfill.ts
|
|
1586
1667
|
var _TextEncoderStream_polyfill = class {
|
|
1587
1668
|
#pendingHighSurrogate = null;
|
|
@@ -1636,13 +1717,15 @@ var _TextEncoderStream_polyfill = class {
|
|
|
1636
1717
|
}
|
|
1637
1718
|
};
|
|
1638
1719
|
export {
|
|
1639
|
-
AbortMessage,
|
|
1640
|
-
RedirectMessage,
|
|
1720
|
+
AbortMessage3 as AbortMessage,
|
|
1721
|
+
RedirectMessage4 as RedirectMessage,
|
|
1641
1722
|
RequestEvShareQData,
|
|
1642
|
-
RewriteMessage,
|
|
1643
|
-
ServerError,
|
|
1723
|
+
RewriteMessage3 as RewriteMessage,
|
|
1724
|
+
ServerError4 as ServerError,
|
|
1644
1725
|
_TextEncoderStream_polyfill,
|
|
1645
1726
|
getErrorHtml,
|
|
1727
|
+
getNotFound,
|
|
1728
|
+
isStaticPath,
|
|
1646
1729
|
mergeHeadersCookies,
|
|
1647
1730
|
requestHandler
|
|
1648
1731
|
};
|