@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
|
@@ -30,246 +30,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// packages/qwik-router/src/middleware/request-handler/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
AbortMessage: () =>
|
|
34
|
-
RedirectMessage: () =>
|
|
33
|
+
AbortMessage: () => AbortMessage3,
|
|
34
|
+
RedirectMessage: () => RedirectMessage4,
|
|
35
35
|
RequestEvShareQData: () => RequestEvShareQData,
|
|
36
|
-
RewriteMessage: () =>
|
|
37
|
-
ServerError: () =>
|
|
36
|
+
RewriteMessage: () => RewriteMessage3,
|
|
37
|
+
ServerError: () => ServerError4,
|
|
38
38
|
_TextEncoderStream_polyfill: () => _TextEncoderStream_polyfill,
|
|
39
39
|
getErrorHtml: () => getErrorHtml,
|
|
40
|
+
getNotFound: () => getNotFound,
|
|
41
|
+
isStaticPath: () => isStaticPath,
|
|
40
42
|
mergeHeadersCookies: () => mergeHeadersCookies,
|
|
41
43
|
requestHandler: () => requestHandler
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(index_exports);
|
|
44
46
|
|
|
45
|
-
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
46
|
-
var ServerError = class extends Error {
|
|
47
|
-
constructor(status, data) {
|
|
48
|
-
super(typeof data === "string" ? data : void 0);
|
|
49
|
-
this.status = status;
|
|
50
|
-
this.data = data;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
function getErrorHtml(status, e) {
|
|
54
|
-
let message = "Server Error";
|
|
55
|
-
if (e != null) {
|
|
56
|
-
if (typeof e.message === "string") {
|
|
57
|
-
message = e.message;
|
|
58
|
-
} else {
|
|
59
|
-
message = String(e);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
|
|
63
|
-
}
|
|
64
|
-
function minimalHtmlResponse(status, message) {
|
|
65
|
-
if (typeof status !== "number") {
|
|
66
|
-
status = 500;
|
|
67
|
-
}
|
|
68
|
-
if (typeof message === "string") {
|
|
69
|
-
message = escapeHtml(message);
|
|
70
|
-
} else {
|
|
71
|
-
message = "";
|
|
72
|
-
}
|
|
73
|
-
const width = typeof message === "string" ? "600px" : "300px";
|
|
74
|
-
const color = status >= 500 ? COLOR_500 : COLOR_400;
|
|
75
|
-
return `
|
|
76
|
-
<head>
|
|
77
|
-
<meta charset="utf-8">
|
|
78
|
-
<meta http-equiv="Status" content="${status}">
|
|
79
|
-
<title>${status} ${message}</title>
|
|
80
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
81
|
-
<style>
|
|
82
|
-
body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
|
|
83
|
-
p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
|
|
84
|
-
strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
|
|
85
|
-
span { display: inline-block; padding: 15px; }
|
|
86
|
-
</style>
|
|
87
|
-
</head>
|
|
88
|
-
<body><p><strong>${status}</strong> <span>${message}</span></p></body>
|
|
89
|
-
`;
|
|
90
|
-
}
|
|
91
|
-
var ESCAPE_HTML = /[&<>]/g;
|
|
92
|
-
var escapeHtml = (s) => {
|
|
93
|
-
return s.replace(ESCAPE_HTML, (c) => {
|
|
94
|
-
switch (c) {
|
|
95
|
-
case "&":
|
|
96
|
-
return "&";
|
|
97
|
-
case "<":
|
|
98
|
-
return "<";
|
|
99
|
-
case ">":
|
|
100
|
-
return ">";
|
|
101
|
-
default:
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
var COLOR_400 = "#006ce9";
|
|
107
|
-
var COLOR_500 = "#713fc2";
|
|
108
|
-
|
|
109
|
-
// packages/qwik-router/src/middleware/request-handler/cookie.ts
|
|
110
|
-
var SAMESITE = {
|
|
111
|
-
lax: "Lax",
|
|
112
|
-
Lax: "Lax",
|
|
113
|
-
None: "None",
|
|
114
|
-
none: "None",
|
|
115
|
-
strict: "Strict",
|
|
116
|
-
Strict: "Strict"
|
|
117
|
-
};
|
|
118
|
-
var UNIT = {
|
|
119
|
-
seconds: 1,
|
|
120
|
-
minutes: 1 * 60,
|
|
121
|
-
hours: 1 * 60 * 60,
|
|
122
|
-
days: 1 * 60 * 60 * 24,
|
|
123
|
-
weeks: 1 * 60 * 60 * 24 * 7
|
|
124
|
-
};
|
|
125
|
-
var createSetCookieValue = (cookieName, cookieValue, options) => {
|
|
126
|
-
const c = [`${cookieName}=${cookieValue}`];
|
|
127
|
-
if (typeof options.domain === "string") {
|
|
128
|
-
c.push(`Domain=${options.domain}`);
|
|
129
|
-
}
|
|
130
|
-
if (typeof options.maxAge === "number") {
|
|
131
|
-
c.push(`Max-Age=${options.maxAge}`);
|
|
132
|
-
} else if (Array.isArray(options.maxAge)) {
|
|
133
|
-
c.push(`Max-Age=${options.maxAge[0] * UNIT[options.maxAge[1]]}`);
|
|
134
|
-
} else if (typeof options.expires === "number" || typeof options.expires == "string") {
|
|
135
|
-
c.push(`Expires=${options.expires}`);
|
|
136
|
-
} else if (options.expires instanceof Date) {
|
|
137
|
-
c.push(`Expires=${options.expires.toUTCString()}`);
|
|
138
|
-
}
|
|
139
|
-
if (options.httpOnly) {
|
|
140
|
-
c.push("HttpOnly");
|
|
141
|
-
}
|
|
142
|
-
if (typeof options.path === "string") {
|
|
143
|
-
c.push(`Path=${options.path}`);
|
|
144
|
-
}
|
|
145
|
-
const sameSite = resolveSameSite(options.sameSite);
|
|
146
|
-
if (sameSite) {
|
|
147
|
-
c.push(`SameSite=${sameSite}`);
|
|
148
|
-
}
|
|
149
|
-
if (options.secure) {
|
|
150
|
-
c.push("Secure");
|
|
151
|
-
}
|
|
152
|
-
return c.join("; ");
|
|
153
|
-
};
|
|
154
|
-
function tryDecodeUriComponent(str) {
|
|
155
|
-
try {
|
|
156
|
-
return decodeURIComponent(str);
|
|
157
|
-
} catch {
|
|
158
|
-
return str;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
var parseCookieString = (cookieString) => {
|
|
162
|
-
const cookie = {};
|
|
163
|
-
if (typeof cookieString === "string" && cookieString !== "") {
|
|
164
|
-
const cookieSegments = cookieString.split(";");
|
|
165
|
-
for (const cookieSegment of cookieSegments) {
|
|
166
|
-
const separatorIndex = cookieSegment.indexOf("=");
|
|
167
|
-
if (separatorIndex !== -1) {
|
|
168
|
-
cookie[tryDecodeUriComponent(cookieSegment.slice(0, separatorIndex).trim())] = tryDecodeUriComponent(cookieSegment.slice(separatorIndex + 1).trim());
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return cookie;
|
|
173
|
-
};
|
|
174
|
-
function resolveSameSite(sameSite) {
|
|
175
|
-
if (sameSite === true) {
|
|
176
|
-
return "Strict";
|
|
177
|
-
}
|
|
178
|
-
if (sameSite === false) {
|
|
179
|
-
return "None";
|
|
180
|
-
}
|
|
181
|
-
if (sameSite) {
|
|
182
|
-
return SAMESITE[sameSite];
|
|
183
|
-
}
|
|
184
|
-
return void 0;
|
|
185
|
-
}
|
|
186
|
-
var REQ_COOKIE = Symbol("request-cookies");
|
|
187
|
-
var RES_COOKIE = Symbol("response-cookies");
|
|
188
|
-
var LIVE_COOKIE = Symbol("live-cookies");
|
|
189
|
-
var Cookie = class {
|
|
190
|
-
[REQ_COOKIE];
|
|
191
|
-
[RES_COOKIE] = {};
|
|
192
|
-
[LIVE_COOKIE] = {};
|
|
193
|
-
appendCounter = 0;
|
|
194
|
-
constructor(cookieString) {
|
|
195
|
-
this[REQ_COOKIE] = parseCookieString(cookieString);
|
|
196
|
-
this[LIVE_COOKIE] = { ...this[REQ_COOKIE] };
|
|
197
|
-
}
|
|
198
|
-
get(cookieName, live = true) {
|
|
199
|
-
const value = this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
200
|
-
if (!value) {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
value,
|
|
205
|
-
json() {
|
|
206
|
-
return JSON.parse(value);
|
|
207
|
-
},
|
|
208
|
-
number() {
|
|
209
|
-
return Number(value);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
getAll(live = true) {
|
|
214
|
-
return Object.keys(this[live ? LIVE_COOKIE : REQ_COOKIE]).reduce(
|
|
215
|
-
(cookies, cookieName) => {
|
|
216
|
-
cookies[cookieName] = this.get(cookieName);
|
|
217
|
-
return cookies;
|
|
218
|
-
},
|
|
219
|
-
{}
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
has(cookieName, live = true) {
|
|
223
|
-
return !!this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
224
|
-
}
|
|
225
|
-
set(cookieName, cookieValue, options = {}) {
|
|
226
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
227
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
228
|
-
this[RES_COOKIE][cookieName] = createSetCookieValue(cookieName, resolvedValue, options);
|
|
229
|
-
}
|
|
230
|
-
append(cookieName, cookieValue, options = {}) {
|
|
231
|
-
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
232
|
-
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
233
|
-
this[RES_COOKIE][++this.appendCounter] = createSetCookieValue(
|
|
234
|
-
cookieName,
|
|
235
|
-
resolvedValue,
|
|
236
|
-
options
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
delete(name, options) {
|
|
240
|
-
this.set(name, "deleted", { ...options, maxAge: 0 });
|
|
241
|
-
this[LIVE_COOKIE][name] = null;
|
|
242
|
-
}
|
|
243
|
-
headers() {
|
|
244
|
-
return Object.values(this[RES_COOKIE]);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
var mergeHeadersCookies = (headers, cookies) => {
|
|
248
|
-
const cookieHeaders = cookies.headers();
|
|
249
|
-
if (cookieHeaders.length > 0) {
|
|
250
|
-
const newHeaders = new Headers(headers);
|
|
251
|
-
for (const cookie of cookieHeaders) {
|
|
252
|
-
newHeaders.append("Set-Cookie", cookie);
|
|
253
|
-
}
|
|
254
|
-
return newHeaders;
|
|
255
|
-
}
|
|
256
|
-
return headers;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// packages/qwik-router/src/middleware/request-handler/redirect-handler.ts
|
|
260
|
-
var AbortMessage = class {
|
|
261
|
-
};
|
|
262
|
-
var RedirectMessage = class extends AbortMessage {
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// packages/qwik-router/src/middleware/request-handler/rewrite-handler.ts
|
|
266
|
-
var RewriteMessage = class extends AbortMessage {
|
|
267
|
-
constructor(pathname) {
|
|
268
|
-
super();
|
|
269
|
-
this.pathname = pathname;
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
47
|
// packages/qwik-router/src/runtime/src/constants.ts
|
|
274
48
|
var MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
275
49
|
var QACTION_KEY = "qaction";
|
|
@@ -499,6 +273,12 @@ var getMenuLoader = (menus, pathname) => {
|
|
|
499
273
|
}
|
|
500
274
|
};
|
|
501
275
|
|
|
276
|
+
// packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts
|
|
277
|
+
var import_internal4 = require("@qwik.dev/core/internal");
|
|
278
|
+
|
|
279
|
+
// packages/qwik-router/src/middleware/request-handler/request-event.ts
|
|
280
|
+
var import_internal3 = require("@qwik.dev/core/internal");
|
|
281
|
+
|
|
502
282
|
// packages/qwik-router/src/middleware/request-handler/cache-control.ts
|
|
503
283
|
function createCacheControl(cacheControl) {
|
|
504
284
|
const controls = [];
|
|
@@ -562,7 +342,218 @@ function createCacheControl(cacheControl) {
|
|
|
562
342
|
return controls.join(", ");
|
|
563
343
|
}
|
|
564
344
|
|
|
345
|
+
// packages/qwik-router/src/middleware/request-handler/cookie.ts
|
|
346
|
+
var SAMESITE = {
|
|
347
|
+
lax: "Lax",
|
|
348
|
+
Lax: "Lax",
|
|
349
|
+
None: "None",
|
|
350
|
+
none: "None",
|
|
351
|
+
strict: "Strict",
|
|
352
|
+
Strict: "Strict"
|
|
353
|
+
};
|
|
354
|
+
var UNIT = {
|
|
355
|
+
seconds: 1,
|
|
356
|
+
minutes: 1 * 60,
|
|
357
|
+
hours: 1 * 60 * 60,
|
|
358
|
+
days: 1 * 60 * 60 * 24,
|
|
359
|
+
weeks: 1 * 60 * 60 * 24 * 7
|
|
360
|
+
};
|
|
361
|
+
var createSetCookieValue = (cookieName, cookieValue, options) => {
|
|
362
|
+
const c = [`${cookieName}=${cookieValue}`];
|
|
363
|
+
if (typeof options.domain === "string") {
|
|
364
|
+
c.push(`Domain=${options.domain}`);
|
|
365
|
+
}
|
|
366
|
+
if (typeof options.maxAge === "number") {
|
|
367
|
+
c.push(`Max-Age=${options.maxAge}`);
|
|
368
|
+
} else if (Array.isArray(options.maxAge)) {
|
|
369
|
+
c.push(`Max-Age=${options.maxAge[0] * UNIT[options.maxAge[1]]}`);
|
|
370
|
+
} else if (typeof options.expires === "number" || typeof options.expires == "string") {
|
|
371
|
+
c.push(`Expires=${options.expires}`);
|
|
372
|
+
} else if (options.expires instanceof Date) {
|
|
373
|
+
c.push(`Expires=${options.expires.toUTCString()}`);
|
|
374
|
+
}
|
|
375
|
+
if (options.httpOnly) {
|
|
376
|
+
c.push("HttpOnly");
|
|
377
|
+
}
|
|
378
|
+
if (typeof options.path === "string") {
|
|
379
|
+
c.push(`Path=${options.path}`);
|
|
380
|
+
}
|
|
381
|
+
const sameSite = resolveSameSite(options.sameSite);
|
|
382
|
+
if (sameSite) {
|
|
383
|
+
c.push(`SameSite=${sameSite}`);
|
|
384
|
+
}
|
|
385
|
+
if (options.secure) {
|
|
386
|
+
c.push("Secure");
|
|
387
|
+
}
|
|
388
|
+
return c.join("; ");
|
|
389
|
+
};
|
|
390
|
+
function tryDecodeUriComponent(str) {
|
|
391
|
+
try {
|
|
392
|
+
return decodeURIComponent(str);
|
|
393
|
+
} catch {
|
|
394
|
+
return str;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
var parseCookieString = (cookieString) => {
|
|
398
|
+
const cookie = {};
|
|
399
|
+
if (typeof cookieString === "string" && cookieString !== "") {
|
|
400
|
+
const cookieSegments = cookieString.split(";");
|
|
401
|
+
for (const cookieSegment of cookieSegments) {
|
|
402
|
+
const separatorIndex = cookieSegment.indexOf("=");
|
|
403
|
+
if (separatorIndex !== -1) {
|
|
404
|
+
cookie[tryDecodeUriComponent(cookieSegment.slice(0, separatorIndex).trim())] = tryDecodeUriComponent(cookieSegment.slice(separatorIndex + 1).trim());
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return cookie;
|
|
409
|
+
};
|
|
410
|
+
function resolveSameSite(sameSite) {
|
|
411
|
+
if (sameSite === true) {
|
|
412
|
+
return "Strict";
|
|
413
|
+
}
|
|
414
|
+
if (sameSite === false) {
|
|
415
|
+
return "None";
|
|
416
|
+
}
|
|
417
|
+
if (sameSite) {
|
|
418
|
+
return SAMESITE[sameSite];
|
|
419
|
+
}
|
|
420
|
+
return void 0;
|
|
421
|
+
}
|
|
422
|
+
var REQ_COOKIE = Symbol("request-cookies");
|
|
423
|
+
var RES_COOKIE = Symbol("response-cookies");
|
|
424
|
+
var LIVE_COOKIE = Symbol("live-cookies");
|
|
425
|
+
var Cookie = class {
|
|
426
|
+
[REQ_COOKIE];
|
|
427
|
+
[RES_COOKIE] = {};
|
|
428
|
+
[LIVE_COOKIE] = {};
|
|
429
|
+
appendCounter = 0;
|
|
430
|
+
constructor(cookieString) {
|
|
431
|
+
this[REQ_COOKIE] = parseCookieString(cookieString);
|
|
432
|
+
this[LIVE_COOKIE] = { ...this[REQ_COOKIE] };
|
|
433
|
+
}
|
|
434
|
+
get(cookieName, live = true) {
|
|
435
|
+
const value = this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
436
|
+
if (!value) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
value,
|
|
441
|
+
json() {
|
|
442
|
+
return JSON.parse(value);
|
|
443
|
+
},
|
|
444
|
+
number() {
|
|
445
|
+
return Number(value);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
getAll(live = true) {
|
|
450
|
+
return Object.keys(this[live ? LIVE_COOKIE : REQ_COOKIE]).reduce(
|
|
451
|
+
(cookies, cookieName) => {
|
|
452
|
+
cookies[cookieName] = this.get(cookieName);
|
|
453
|
+
return cookies;
|
|
454
|
+
},
|
|
455
|
+
{}
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
has(cookieName, live = true) {
|
|
459
|
+
return !!this[live ? LIVE_COOKIE : REQ_COOKIE][cookieName];
|
|
460
|
+
}
|
|
461
|
+
set(cookieName, cookieValue, options = {}) {
|
|
462
|
+
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
463
|
+
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
464
|
+
this[RES_COOKIE][cookieName] = createSetCookieValue(cookieName, resolvedValue, options);
|
|
465
|
+
}
|
|
466
|
+
append(cookieName, cookieValue, options = {}) {
|
|
467
|
+
this[LIVE_COOKIE][cookieName] = typeof cookieValue === "string" ? cookieValue : JSON.stringify(cookieValue);
|
|
468
|
+
const resolvedValue = typeof cookieValue === "string" ? cookieValue : encodeURIComponent(JSON.stringify(cookieValue));
|
|
469
|
+
this[RES_COOKIE][++this.appendCounter] = createSetCookieValue(
|
|
470
|
+
cookieName,
|
|
471
|
+
resolvedValue,
|
|
472
|
+
options
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
delete(name, options) {
|
|
476
|
+
this.set(name, "deleted", { ...options, maxAge: 0 });
|
|
477
|
+
this[LIVE_COOKIE][name] = null;
|
|
478
|
+
}
|
|
479
|
+
headers() {
|
|
480
|
+
return Object.values(this[RES_COOKIE]);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
var mergeHeadersCookies = (headers, cookies) => {
|
|
484
|
+
const cookieHeaders = cookies.headers();
|
|
485
|
+
if (cookieHeaders.length > 0) {
|
|
486
|
+
const newHeaders = new Headers(headers);
|
|
487
|
+
for (const cookie of cookieHeaders) {
|
|
488
|
+
newHeaders.append("Set-Cookie", cookie);
|
|
489
|
+
}
|
|
490
|
+
return newHeaders;
|
|
491
|
+
}
|
|
492
|
+
return headers;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// packages/qwik-router/src/middleware/request-handler/request-event.ts
|
|
496
|
+
var import_request_handler2 = require("@qwik.dev/router/middleware/request-handler");
|
|
497
|
+
|
|
498
|
+
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
499
|
+
function getErrorHtml(status, e) {
|
|
500
|
+
let message = "Server Error";
|
|
501
|
+
if (e != null) {
|
|
502
|
+
if (typeof e.message === "string") {
|
|
503
|
+
message = e.message;
|
|
504
|
+
} else {
|
|
505
|
+
message = String(e);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return `<html>` + minimalHtmlResponse(status, message) + `</html>`;
|
|
509
|
+
}
|
|
510
|
+
function minimalHtmlResponse(status, message) {
|
|
511
|
+
if (typeof status !== "number") {
|
|
512
|
+
status = 500;
|
|
513
|
+
}
|
|
514
|
+
if (typeof message === "string") {
|
|
515
|
+
message = escapeHtml(message);
|
|
516
|
+
} else {
|
|
517
|
+
message = "";
|
|
518
|
+
}
|
|
519
|
+
const width = typeof message === "string" ? "600px" : "300px";
|
|
520
|
+
const color = status >= 500 ? COLOR_500 : COLOR_400;
|
|
521
|
+
return `
|
|
522
|
+
<head>
|
|
523
|
+
<meta charset="utf-8">
|
|
524
|
+
<meta http-equiv="Status" content="${status}">
|
|
525
|
+
<title>${status} ${message}</title>
|
|
526
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
527
|
+
<style>
|
|
528
|
+
body { color: ${color}; background-color: #fafafa; padding: 30px; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
|
|
529
|
+
p { max-width: ${width}; margin: 60px auto 30px auto; background: white; border-radius: 4px; box-shadow: 0px 0px 50px -20px ${color}; overflow: hidden; }
|
|
530
|
+
strong { display: inline-block; padding: 15px; background: ${color}; color: white; }
|
|
531
|
+
span { display: inline-block; padding: 15px; }
|
|
532
|
+
</style>
|
|
533
|
+
</head>
|
|
534
|
+
<body><p><strong>${status}</strong> <span>${message}</span></p></body>
|
|
535
|
+
`;
|
|
536
|
+
}
|
|
537
|
+
var ESCAPE_HTML = /[&<>]/g;
|
|
538
|
+
var escapeHtml = (s) => {
|
|
539
|
+
return s.replace(ESCAPE_HTML, (c) => {
|
|
540
|
+
switch (c) {
|
|
541
|
+
case "&":
|
|
542
|
+
return "&";
|
|
543
|
+
case "<":
|
|
544
|
+
return "<";
|
|
545
|
+
case ">":
|
|
546
|
+
return ">";
|
|
547
|
+
default:
|
|
548
|
+
return "";
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
var COLOR_400 = "#006ce9";
|
|
553
|
+
var COLOR_500 = "#713fc2";
|
|
554
|
+
|
|
565
555
|
// packages/qwik-router/src/middleware/request-handler/user-response.ts
|
|
556
|
+
var import_request_handler = require("@qwik.dev/router/middleware/request-handler");
|
|
566
557
|
var asyncStore;
|
|
567
558
|
import("node:async_hooks").then((module2) => {
|
|
568
559
|
const AsyncLocalStorage = module2.AsyncLocalStorage;
|
|
@@ -574,14 +565,13 @@ import("node:async_hooks").then((module2) => {
|
|
|
574
565
|
err
|
|
575
566
|
);
|
|
576
567
|
});
|
|
577
|
-
function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo,
|
|
568
|
+
function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, basePathname = "/", qwikSerializer) {
|
|
578
569
|
let resolve;
|
|
579
570
|
const responsePromise = new Promise((r) => resolve = r);
|
|
580
571
|
const requestEv = createRequestEvent(
|
|
581
572
|
serverRequestEv,
|
|
582
573
|
loadedRoute,
|
|
583
574
|
requestHandlers,
|
|
584
|
-
trailingSlash,
|
|
585
575
|
basePathname,
|
|
586
576
|
qwikSerializer,
|
|
587
577
|
resolve
|
|
@@ -598,10 +588,10 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
598
588
|
try {
|
|
599
589
|
await requestEv.next();
|
|
600
590
|
} catch (e) {
|
|
601
|
-
if (e instanceof RedirectMessage) {
|
|
591
|
+
if (e instanceof import_request_handler.RedirectMessage) {
|
|
602
592
|
const stream = requestEv.getWritableStream();
|
|
603
593
|
await stream.close();
|
|
604
|
-
} else if (e instanceof RewriteMessage) {
|
|
594
|
+
} else if (e instanceof import_request_handler.RewriteMessage) {
|
|
605
595
|
if (rewriteAttempt > 50) {
|
|
606
596
|
throw new Error(`Infinite rewrite loop`);
|
|
607
597
|
}
|
|
@@ -611,7 +601,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
611
601
|
const { loadedRoute, requestHandlers } = await rebuildRouteInfo(url);
|
|
612
602
|
requestEv.resetRoute(loadedRoute, requestHandlers, url);
|
|
613
603
|
return await _runNext();
|
|
614
|
-
} else if (e instanceof ServerError) {
|
|
604
|
+
} else if (e instanceof import_request_handler.ServerError) {
|
|
615
605
|
if (!requestEv.headersSent) {
|
|
616
606
|
const status = e.status;
|
|
617
607
|
const accept = requestEv.request.headers.get("Accept");
|
|
@@ -624,7 +614,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
624
614
|
requestEv.html(status, html);
|
|
625
615
|
}
|
|
626
616
|
}
|
|
627
|
-
} else if (!(e instanceof AbortMessage)) {
|
|
617
|
+
} else if (!(e instanceof import_request_handler.AbortMessage)) {
|
|
628
618
|
if (getRequestMode(requestEv) !== "dev") {
|
|
629
619
|
try {
|
|
630
620
|
if (!requestEv.headersSent) {
|
|
@@ -635,7 +625,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
635
625
|
const stream = requestEv.getWritableStream();
|
|
636
626
|
if (!stream.locked) {
|
|
637
627
|
const writer = stream.getWriter();
|
|
638
|
-
await writer.write(encoder.encode(
|
|
628
|
+
await writer.write(encoder.encode(getErrorHtml(500, "Internal Server Error")));
|
|
639
629
|
await writer.close();
|
|
640
630
|
}
|
|
641
631
|
} catch {
|
|
@@ -655,9 +645,9 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
|
|
|
655
645
|
}
|
|
656
646
|
}
|
|
657
647
|
}
|
|
658
|
-
function getRouteMatchPathname(pathname
|
|
648
|
+
function getRouteMatchPathname(pathname) {
|
|
659
649
|
if (pathname.endsWith(QDATA_JSON)) {
|
|
660
|
-
const trimEnd = pathname.length - QDATA_JSON_LEN + (
|
|
650
|
+
const trimEnd = pathname.length - QDATA_JSON_LEN + (globalThis.__NO_TRAILING_SLASH__ ? 0 : 1);
|
|
661
651
|
pathname = pathname.slice(0, trimEnd);
|
|
662
652
|
if (pathname === "") {
|
|
663
653
|
pathname = "/";
|
|
@@ -677,7 +667,6 @@ var RequestEvQwikSerializer = Symbol("RequestEvQwikSerializer");
|
|
|
677
667
|
var RequestEvLoaderSerializationStrategyMap = Symbol(
|
|
678
668
|
"RequestEvLoaderSerializationStrategyMap"
|
|
679
669
|
);
|
|
680
|
-
var RequestEvTrailingSlash = Symbol("RequestEvTrailingSlash");
|
|
681
670
|
var RequestRouteName = "@routeName";
|
|
682
671
|
var RequestEvSharedActionId = "@actionId";
|
|
683
672
|
var RequestEvSharedActionFormData = "@actionFormData";
|
|
@@ -685,7 +674,7 @@ var RequestEvSharedNonce = "@nonce";
|
|
|
685
674
|
var RequestEvIsRewrite = "@rewrite";
|
|
686
675
|
var RequestEvShareServerTiming = "@serverTiming";
|
|
687
676
|
var RequestEvShareQData = "qData";
|
|
688
|
-
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers,
|
|
677
|
+
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, basePathname, qwikSerializer, resolved) {
|
|
689
678
|
const { request, platform, env } = serverRequestEv;
|
|
690
679
|
const sharedMap = /* @__PURE__ */ new Map();
|
|
691
680
|
const cookie = new Cookie(request.headers.get("cookie"));
|
|
@@ -693,7 +682,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
693
682
|
const url = new URL(request.url);
|
|
694
683
|
if (url.pathname.endsWith(QDATA_JSON)) {
|
|
695
684
|
url.pathname = url.pathname.slice(0, -QDATA_JSON_LEN);
|
|
696
|
-
if (
|
|
685
|
+
if (!globalThis.__NO_TRAILING_SLASH__ && !url.pathname.endsWith("/")) {
|
|
697
686
|
url.pathname += "/";
|
|
698
687
|
}
|
|
699
688
|
sharedMap.set(IsQData, true);
|
|
@@ -763,14 +752,13 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
763
752
|
};
|
|
764
753
|
const exit = () => {
|
|
765
754
|
routeModuleIndex = ABORT_INDEX;
|
|
766
|
-
return new AbortMessage();
|
|
755
|
+
return new import_request_handler2.AbortMessage();
|
|
767
756
|
};
|
|
768
757
|
const loaders = {};
|
|
769
758
|
const requestEv = {
|
|
770
759
|
[RequestEvLoaders]: loaders,
|
|
771
760
|
[RequestEvLoaderSerializationStrategyMap]: /* @__PURE__ */ new Map(),
|
|
772
761
|
[RequestEvMode]: serverRequestEv.mode,
|
|
773
|
-
[RequestEvTrailingSlash]: trailingSlash,
|
|
774
762
|
get [RequestEvRoute]() {
|
|
775
763
|
return loadedRoute;
|
|
776
764
|
},
|
|
@@ -819,6 +807,10 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
819
807
|
"You can not get the returned data of a loader that has not been executed for this request."
|
|
820
808
|
);
|
|
821
809
|
}
|
|
810
|
+
if (loaders[id] === import_internal3._UNINITIALIZED) {
|
|
811
|
+
const isDev = getRequestMode(requestEv) === "dev";
|
|
812
|
+
await getRouteLoaderPromise(loaderOrAction, loaders, requestEv, isDev, qwikSerializer);
|
|
813
|
+
}
|
|
822
814
|
}
|
|
823
815
|
return loaders[id];
|
|
824
816
|
},
|
|
@@ -838,7 +830,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
838
830
|
},
|
|
839
831
|
error: (statusCode, message) => {
|
|
840
832
|
status = statusCode;
|
|
841
|
-
return new ServerError(statusCode, message);
|
|
833
|
+
return new import_request_handler2.ServerError(statusCode, message);
|
|
842
834
|
},
|
|
843
835
|
redirect: (statusCode, url2) => {
|
|
844
836
|
check();
|
|
@@ -854,7 +846,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
854
846
|
headers.set("Cache-Control", "no-store");
|
|
855
847
|
}
|
|
856
848
|
exit();
|
|
857
|
-
return new RedirectMessage();
|
|
849
|
+
return new import_request_handler2.RedirectMessage();
|
|
858
850
|
},
|
|
859
851
|
rewrite: (pathname) => {
|
|
860
852
|
check();
|
|
@@ -862,7 +854,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
|
|
|
862
854
|
throw new Error("Rewrite does not support absolute urls");
|
|
863
855
|
}
|
|
864
856
|
sharedMap.set(RequestEvIsRewrite, true);
|
|
865
|
-
return new RewriteMessage(pathname.replace(/\/+/g, "/"));
|
|
857
|
+
return new import_request_handler2.RewriteMessage(pathname.replace(/\/+/g, "/"));
|
|
866
858
|
},
|
|
867
859
|
defer: (returnData) => {
|
|
868
860
|
return typeof returnData === "function" ? returnData : () => returnData;
|
|
@@ -927,9 +919,6 @@ function getRequestLoaders(requestEv) {
|
|
|
927
919
|
function getRequestLoaderSerializationStrategyMap(requestEv) {
|
|
928
920
|
return requestEv[RequestEvLoaderSerializationStrategyMap];
|
|
929
921
|
}
|
|
930
|
-
function getRequestTrailingSlash(requestEv) {
|
|
931
|
-
return requestEv[RequestEvTrailingSlash];
|
|
932
|
-
}
|
|
933
922
|
function getRequestRoute(requestEv) {
|
|
934
923
|
return requestEv[RequestEvRoute];
|
|
935
924
|
}
|
|
@@ -1026,6 +1015,7 @@ function getQwikRouterServerData(requestEv) {
|
|
|
1026
1015
|
}
|
|
1027
1016
|
|
|
1028
1017
|
// packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts
|
|
1018
|
+
var import_request_handler3 = require("@qwik.dev/router/middleware/request-handler");
|
|
1029
1019
|
var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderHandler) => {
|
|
1030
1020
|
const routeLoaders = [];
|
|
1031
1021
|
const routeActions = [];
|
|
@@ -1045,6 +1035,9 @@ var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderH
|
|
|
1045
1035
|
const routeName = route[0 /* RouteName */];
|
|
1046
1036
|
if (checkOrigin && (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE")) {
|
|
1047
1037
|
requestHandlers.unshift(csrfCheckMiddleware);
|
|
1038
|
+
if (checkOrigin === "lax-proto") {
|
|
1039
|
+
requestHandlers.push(csrfLaxProtoCheckMiddleware);
|
|
1040
|
+
}
|
|
1048
1041
|
}
|
|
1049
1042
|
if (isPageRoute) {
|
|
1050
1043
|
if (method === "POST" || method === "GET") {
|
|
@@ -1197,6 +1190,8 @@ function loadersMiddleware(routeLoaders) {
|
|
|
1197
1190
|
for (const loader of routeLoaders) {
|
|
1198
1191
|
if (selectedLoaderIds.includes(loader.__id)) {
|
|
1199
1192
|
currentLoaders.push(loader);
|
|
1193
|
+
} else {
|
|
1194
|
+
loaders[loader.__id] = import_internal4._UNINITIALIZED;
|
|
1200
1195
|
}
|
|
1201
1196
|
}
|
|
1202
1197
|
} else {
|
|
@@ -1296,7 +1291,7 @@ async function pureServerFunction(ev) {
|
|
|
1296
1291
|
result = await qrl.apply(ev, args);
|
|
1297
1292
|
}
|
|
1298
1293
|
} catch (err) {
|
|
1299
|
-
if (err instanceof ServerError) {
|
|
1294
|
+
if (err instanceof import_request_handler3.ServerError) {
|
|
1300
1295
|
throw ev.error(err.status, err.data);
|
|
1301
1296
|
}
|
|
1302
1297
|
throw ev.error(500, "Invalid request");
|
|
@@ -1330,12 +1325,11 @@ async function pureServerFunction(ev) {
|
|
|
1330
1325
|
}
|
|
1331
1326
|
}
|
|
1332
1327
|
function fixTrailingSlash(ev) {
|
|
1333
|
-
const trailingSlash = getRequestTrailingSlash(ev);
|
|
1334
1328
|
const { basePathname, originalUrl, sharedMap } = ev;
|
|
1335
1329
|
const { pathname, search } = originalUrl;
|
|
1336
1330
|
const isQData = sharedMap.has(IsQData);
|
|
1337
1331
|
if (!isQData && pathname !== basePathname && !pathname.endsWith(".html")) {
|
|
1338
|
-
if (
|
|
1332
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1339
1333
|
if (!pathname.endsWith("/")) {
|
|
1340
1334
|
throw ev.redirect(301 /* MovedPermanently */, pathname + "/" + search);
|
|
1341
1335
|
}
|
|
@@ -1366,12 +1360,12 @@ function isLastModulePageRoute(routeModules) {
|
|
|
1366
1360
|
const lastRouteModule = routeModules[routeModules.length - 1];
|
|
1367
1361
|
return lastRouteModule && typeof lastRouteModule.default === "function";
|
|
1368
1362
|
}
|
|
1369
|
-
function getPathname(url
|
|
1363
|
+
function getPathname(url) {
|
|
1370
1364
|
url = new URL(url);
|
|
1371
1365
|
if (url.pathname.endsWith(QDATA_JSON)) {
|
|
1372
1366
|
url.pathname = url.pathname.slice(0, -QDATA_JSON.length);
|
|
1373
1367
|
}
|
|
1374
|
-
if (
|
|
1368
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1375
1369
|
if (!url.pathname.endsWith("/")) {
|
|
1376
1370
|
url.pathname += "/";
|
|
1377
1371
|
}
|
|
@@ -1384,7 +1378,13 @@ function getPathname(url, trailingSlash) {
|
|
|
1384
1378
|
return `${url.pathname}${search ? `?${search}` : ""}${url.hash}`;
|
|
1385
1379
|
}
|
|
1386
1380
|
var encoder = /* @__PURE__ */ new TextEncoder();
|
|
1381
|
+
function csrfLaxProtoCheckMiddleware(requestEv) {
|
|
1382
|
+
checkCSRF(requestEv, "lax-proto");
|
|
1383
|
+
}
|
|
1387
1384
|
function csrfCheckMiddleware(requestEv) {
|
|
1385
|
+
checkCSRF(requestEv);
|
|
1386
|
+
}
|
|
1387
|
+
function checkCSRF(requestEv, laxProto) {
|
|
1388
1388
|
const isForm = isContentType(
|
|
1389
1389
|
requestEv.request.headers,
|
|
1390
1390
|
"application/x-www-form-urlencoded",
|
|
@@ -1394,7 +1394,10 @@ function csrfCheckMiddleware(requestEv) {
|
|
|
1394
1394
|
if (isForm) {
|
|
1395
1395
|
const inputOrigin = requestEv.request.headers.get("origin");
|
|
1396
1396
|
const origin = requestEv.url.origin;
|
|
1397
|
-
|
|
1397
|
+
let forbidden = inputOrigin !== origin;
|
|
1398
|
+
if (forbidden && laxProto && origin.startsWith("https://") && (inputOrigin == null ? void 0 : inputOrigin.slice(4)) === origin.slice(5)) {
|
|
1399
|
+
forbidden = false;
|
|
1400
|
+
}
|
|
1398
1401
|
if (forbidden) {
|
|
1399
1402
|
throw requestEv.error(
|
|
1400
1403
|
403,
|
|
@@ -1419,7 +1422,6 @@ function renderQwikMiddleware(render) {
|
|
|
1419
1422
|
if (!responseHeaders.has("Content-Type")) {
|
|
1420
1423
|
responseHeaders.set("Content-Type", "text/html; charset=utf-8");
|
|
1421
1424
|
}
|
|
1422
|
-
const trailingSlash = getRequestTrailingSlash(requestEv);
|
|
1423
1425
|
const { readable, writable } = new TextEncoderStream();
|
|
1424
1426
|
const writableStream = requestEv.getWritableStream();
|
|
1425
1427
|
const pipe = readable.pipeTo(writableStream, { preventClose: true });
|
|
@@ -1441,7 +1443,7 @@ function renderQwikMiddleware(render) {
|
|
|
1441
1443
|
loaders: getRequestLoaders(requestEv),
|
|
1442
1444
|
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1443
1445
|
status: status !== 200 ? status : 200,
|
|
1444
|
-
href: getPathname(requestEv.url
|
|
1446
|
+
href: getPathname(requestEv.url)
|
|
1445
1447
|
};
|
|
1446
1448
|
if (typeof result.html === "string") {
|
|
1447
1449
|
await stream.write(result.html);
|
|
@@ -1463,7 +1465,7 @@ async function handleRedirect(requestEv) {
|
|
|
1463
1465
|
try {
|
|
1464
1466
|
await requestEv.next();
|
|
1465
1467
|
} catch (err) {
|
|
1466
|
-
if (!(err instanceof RedirectMessage)) {
|
|
1468
|
+
if (!(err instanceof import_request_handler3.RedirectMessage)) {
|
|
1467
1469
|
throw err;
|
|
1468
1470
|
}
|
|
1469
1471
|
}
|
|
@@ -1496,7 +1498,6 @@ async function renderQData(requestEv) {
|
|
|
1496
1498
|
}
|
|
1497
1499
|
const status = requestEv.status();
|
|
1498
1500
|
const redirectLocation = requestEv.headers.get("Location");
|
|
1499
|
-
const trailingSlash = getRequestTrailingSlash(requestEv);
|
|
1500
1501
|
const requestHeaders = {};
|
|
1501
1502
|
requestEv.request.headers.forEach((value, key) => requestHeaders[key] = value);
|
|
1502
1503
|
requestEv.headers.set("Content-Type", "application/json; charset=utf-8");
|
|
@@ -1515,12 +1516,12 @@ async function renderQData(requestEv) {
|
|
|
1515
1516
|
// send minimal data to the client
|
|
1516
1517
|
loaders,
|
|
1517
1518
|
status: status !== 200 ? status : 200,
|
|
1518
|
-
href: getPathname(requestEv.url
|
|
1519
|
+
href: getPathname(requestEv.url)
|
|
1519
1520
|
} : {
|
|
1520
1521
|
loaders,
|
|
1521
1522
|
action: requestEv.sharedMap.get(RequestEvSharedActionId),
|
|
1522
1523
|
status: status !== 200 ? status : 200,
|
|
1523
|
-
href: getPathname(requestEv.url
|
|
1524
|
+
href: getPathname(requestEv.url),
|
|
1524
1525
|
redirect: redirectLocation ?? void 0,
|
|
1525
1526
|
isRewrite: requestEv.sharedMap.get(RequestEvIsRewrite)
|
|
1526
1527
|
};
|
|
@@ -1564,13 +1565,21 @@ function isContentType(headers, ...types) {
|
|
|
1564
1565
|
}
|
|
1565
1566
|
|
|
1566
1567
|
// packages/qwik-router/src/middleware/request-handler/request-handler.ts
|
|
1568
|
+
var qwikRouterConfigActual;
|
|
1567
1569
|
async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
1568
|
-
const { render,
|
|
1570
|
+
const { render, checkOrigin } = opts;
|
|
1571
|
+
let { qwikRouterConfig } = opts;
|
|
1572
|
+
if (!qwikRouterConfig) {
|
|
1573
|
+
if (!qwikRouterConfigActual) {
|
|
1574
|
+
qwikRouterConfigActual = await import("@qwik-router-config");
|
|
1575
|
+
}
|
|
1576
|
+
qwikRouterConfig = qwikRouterConfigActual;
|
|
1577
|
+
}
|
|
1569
1578
|
if (!qwikRouterConfig) {
|
|
1570
1579
|
throw new Error("qwikRouterConfig is required.");
|
|
1571
1580
|
}
|
|
1572
1581
|
const pathname = serverRequestEv.url.pathname;
|
|
1573
|
-
const matchPathname = getRouteMatchPathname(pathname
|
|
1582
|
+
const matchPathname = getRouteMatchPathname(pathname);
|
|
1574
1583
|
const routeAndHandlers = await loadRequestHandlers(
|
|
1575
1584
|
qwikRouterConfig,
|
|
1576
1585
|
matchPathname,
|
|
@@ -1581,7 +1590,7 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
|
1581
1590
|
if (routeAndHandlers) {
|
|
1582
1591
|
const [route, requestHandlers] = routeAndHandlers;
|
|
1583
1592
|
const rebuildRouteInfo = async (url) => {
|
|
1584
|
-
const matchPathname2 = getRouteMatchPathname(url.pathname
|
|
1593
|
+
const matchPathname2 = getRouteMatchPathname(url.pathname);
|
|
1585
1594
|
const routeAndHandlers2 = await loadRequestHandlers(
|
|
1586
1595
|
qwikRouterConfig,
|
|
1587
1596
|
matchPathname2,
|
|
@@ -1601,7 +1610,6 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
|
|
|
1601
1610
|
route,
|
|
1602
1611
|
requestHandlers,
|
|
1603
1612
|
rebuildRouteInfo,
|
|
1604
|
-
qwikRouterConfig.trailingSlash,
|
|
1605
1613
|
qwikRouterConfig.basePathname,
|
|
1606
1614
|
qwikSerializer
|
|
1607
1615
|
);
|
|
@@ -1624,6 +1632,71 @@ async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrig
|
|
|
1624
1632
|
return null;
|
|
1625
1633
|
}
|
|
1626
1634
|
|
|
1635
|
+
// packages/qwik-router/src/middleware/request-handler/not-found-paths.ts
|
|
1636
|
+
var notFounds = [
|
|
1637
|
+
// Will be replaced in post-build with the 404s generated by SSG
|
|
1638
|
+
"__QWIK_ROUTER_NOT_FOUND_ARRAY__"
|
|
1639
|
+
];
|
|
1640
|
+
function getNotFound(prefix) {
|
|
1641
|
+
for (const [path, html] of notFounds) {
|
|
1642
|
+
if (prefix.startsWith(path)) {
|
|
1643
|
+
return html;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return minimalHtmlResponse(404, "Resource Not Found");
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
// packages/qwik-router/src/middleware/request-handler/static-paths.ts
|
|
1650
|
+
var staticPaths = /* @__PURE__ */ new Set(["__QWIK_ROUTER_STATIC_PATHS_ARRAY__"]);
|
|
1651
|
+
function isStaticPath(method, url) {
|
|
1652
|
+
if (method.toUpperCase() !== "GET") {
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
const p = url.pathname;
|
|
1656
|
+
if (p.startsWith("/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/")) {
|
|
1657
|
+
return true;
|
|
1658
|
+
}
|
|
1659
|
+
if (p.startsWith("/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/")) {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
if (staticPaths.has(p)) {
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
if (p.endsWith("/q-data.json")) {
|
|
1666
|
+
const pWithoutQdata = p.replace(/\/q-data.json$/, "");
|
|
1667
|
+
if (staticPaths.has(pWithoutQdata + "/")) {
|
|
1668
|
+
return true;
|
|
1669
|
+
}
|
|
1670
|
+
if (staticPaths.has(pWithoutQdata)) {
|
|
1671
|
+
return true;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return false;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// packages/qwik-router/src/middleware/request-handler/server-error.ts
|
|
1678
|
+
var ServerError4 = class extends Error {
|
|
1679
|
+
constructor(status, data) {
|
|
1680
|
+
super(typeof data === "string" ? data : void 0);
|
|
1681
|
+
this.status = status;
|
|
1682
|
+
this.data = data;
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
|
|
1686
|
+
// packages/qwik-router/src/middleware/request-handler/redirect-handler.ts
|
|
1687
|
+
var AbortMessage3 = class {
|
|
1688
|
+
};
|
|
1689
|
+
var RedirectMessage4 = class extends AbortMessage3 {
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
// packages/qwik-router/src/middleware/request-handler/rewrite-handler.ts
|
|
1693
|
+
var RewriteMessage3 = class extends AbortMessage3 {
|
|
1694
|
+
constructor(pathname) {
|
|
1695
|
+
super();
|
|
1696
|
+
this.pathname = pathname;
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1627
1700
|
// packages/qwik-router/src/middleware/request-handler/polyfill.ts
|
|
1628
1701
|
var _TextEncoderStream_polyfill = class {
|
|
1629
1702
|
#pendingHighSurrogate = null;
|
|
@@ -1686,6 +1759,8 @@ var _TextEncoderStream_polyfill = class {
|
|
|
1686
1759
|
ServerError,
|
|
1687
1760
|
_TextEncoderStream_polyfill,
|
|
1688
1761
|
getErrorHtml,
|
|
1762
|
+
getNotFound,
|
|
1763
|
+
isStaticPath,
|
|
1689
1764
|
mergeHeadersCookies,
|
|
1690
1765
|
requestHandler
|
|
1691
1766
|
});
|