@qwik.dev/router 2.0.0-beta.5 → 2.0.0-beta.7

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.
Files changed (50) hide show
  1. package/adapters/static/vite.d.ts +1 -1
  2. package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
  3. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  4. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  5. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  6. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  7. package/lib/adapters/netlify-edge/vite/index.cjs +1 -0
  8. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  9. package/lib/adapters/netlify-edge/vite/index.mjs +1 -0
  10. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/shared/vite/index.cjs +88 -128
  12. package/lib/adapters/shared/vite/index.d.ts +9 -15
  13. package/lib/adapters/shared/vite/index.mjs +88 -124
  14. package/lib/adapters/{static → ssg}/vite/index.cjs +95 -124
  15. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  16. package/lib/adapters/{static → ssg}/vite/index.mjs +93 -123
  17. package/lib/adapters/vercel-edge/vite/index.d.ts +2 -2
  18. package/lib/index.d.ts +161 -48
  19. package/lib/index.qwik.cjs +86 -23
  20. package/lib/index.qwik.mjs +88 -25
  21. package/lib/middleware/aws-lambda/index.d.ts +3 -2
  22. package/lib/middleware/aws-lambda/index.mjs +2 -4
  23. package/lib/middleware/azure-swa/index.mjs +6 -6
  24. package/lib/middleware/bun/index.mjs +4 -6
  25. package/lib/middleware/cloudflare-pages/index.mjs +4 -6
  26. package/lib/middleware/deno/index.mjs +8 -7
  27. package/lib/middleware/firebase/index.mjs +1 -3
  28. package/lib/middleware/netlify-edge/index.mjs +7 -6
  29. package/lib/middleware/node/index.cjs +4 -8
  30. package/lib/middleware/node/index.mjs +7 -7
  31. package/lib/middleware/request-handler/index.cjs +331 -268
  32. package/lib/middleware/request-handler/index.d.ts +56 -49
  33. package/lib/middleware/request-handler/index.mjs +335 -264
  34. package/lib/middleware/vercel-edge/index.mjs +7 -6
  35. package/lib/modules.d.ts +4 -12
  36. package/lib/{static → ssg}/deno.mjs +1 -1
  37. package/lib/{static → ssg}/index.cjs +1 -1
  38. package/lib/{static → ssg}/index.d.ts +17 -17
  39. package/lib/{static → ssg}/index.mjs +1 -1
  40. package/lib/{static → ssg}/node.cjs +16 -16
  41. package/lib/{static → ssg}/node.mjs +15 -15
  42. package/lib/vite/index.cjs +10260 -10437
  43. package/lib/vite/index.mjs +8220 -8387
  44. package/modules.d.ts +4 -12
  45. package/package.json +19 -8
  46. package/ssg.d.ts +2 -0
  47. package/static.d.ts +1 -1
  48. package/lib/adapters/static/vite/index.d.ts +0 -10
  49. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  50. 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: () => AbortMessage,
34
- RedirectMessage: () => RedirectMessage,
33
+ AbortMessage: () => AbortMessage3,
34
+ RedirectMessage: () => RedirectMessage4,
35
35
  RequestEvShareQData: () => RequestEvShareQData,
36
- RewriteMessage: () => RewriteMessage,
37
- ServerError: () => 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 "&amp;";
97
- case "<":
98
- return "&lt;";
99
- case ">":
100
- return "&gt;";
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";
@@ -568,7 +342,218 @@ function createCacheControl(cacheControl) {
568
342
  return controls.join(", ");
569
343
  }
570
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 "&amp;";
543
+ case "<":
544
+ return "&lt;";
545
+ case ">":
546
+ return "&gt;";
547
+ default:
548
+ return "";
549
+ }
550
+ });
551
+ };
552
+ var COLOR_400 = "#006ce9";
553
+ var COLOR_500 = "#713fc2";
554
+
571
555
  // packages/qwik-router/src/middleware/request-handler/user-response.ts
556
+ var import_request_handler = require("@qwik.dev/router/middleware/request-handler");
572
557
  var asyncStore;
573
558
  import("node:async_hooks").then((module2) => {
574
559
  const AsyncLocalStorage = module2.AsyncLocalStorage;
@@ -580,14 +565,13 @@ import("node:async_hooks").then((module2) => {
580
565
  err
581
566
  );
582
567
  });
583
- function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, trailingSlash = true, basePathname = "/", qwikSerializer) {
568
+ function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, basePathname = "/", qwikSerializer) {
584
569
  let resolve;
585
570
  const responsePromise = new Promise((r) => resolve = r);
586
571
  const requestEv = createRequestEvent(
587
572
  serverRequestEv,
588
573
  loadedRoute,
589
574
  requestHandlers,
590
- trailingSlash,
591
575
  basePathname,
592
576
  qwikSerializer,
593
577
  resolve
@@ -604,10 +588,10 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
604
588
  try {
605
589
  await requestEv.next();
606
590
  } catch (e) {
607
- if (e instanceof RedirectMessage) {
591
+ if (e instanceof import_request_handler.RedirectMessage) {
608
592
  const stream = requestEv.getWritableStream();
609
593
  await stream.close();
610
- } else if (e instanceof RewriteMessage) {
594
+ } else if (e instanceof import_request_handler.RewriteMessage) {
611
595
  if (rewriteAttempt > 50) {
612
596
  throw new Error(`Infinite rewrite loop`);
613
597
  }
@@ -617,7 +601,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
617
601
  const { loadedRoute, requestHandlers } = await rebuildRouteInfo(url);
618
602
  requestEv.resetRoute(loadedRoute, requestHandlers, url);
619
603
  return await _runNext();
620
- } else if (e instanceof ServerError) {
604
+ } else if (e instanceof import_request_handler.ServerError) {
621
605
  if (!requestEv.headersSent) {
622
606
  const status = e.status;
623
607
  const accept = requestEv.request.headers.get("Accept");
@@ -630,7 +614,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
630
614
  requestEv.html(status, html);
631
615
  }
632
616
  }
633
- } else if (!(e instanceof AbortMessage)) {
617
+ } else if (!(e instanceof import_request_handler.AbortMessage)) {
634
618
  if (getRequestMode(requestEv) !== "dev") {
635
619
  try {
636
620
  if (!requestEv.headersSent) {
@@ -641,7 +625,7 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
641
625
  const stream = requestEv.getWritableStream();
642
626
  if (!stream.locked) {
643
627
  const writer = stream.getWriter();
644
- await writer.write(encoder.encode(minimalHtmlResponse(500, "Internal Server Error")));
628
+ await writer.write(encoder.encode(getErrorHtml(500, "Internal Server Error")));
645
629
  await writer.close();
646
630
  }
647
631
  } catch {
@@ -661,9 +645,9 @@ async function runNext(requestEv, rebuildRouteInfo, resolve) {
661
645
  }
662
646
  }
663
647
  }
664
- function getRouteMatchPathname(pathname, trailingSlash) {
648
+ function getRouteMatchPathname(pathname) {
665
649
  if (pathname.endsWith(QDATA_JSON)) {
666
- const trimEnd = pathname.length - QDATA_JSON_LEN + (trailingSlash ? 1 : 0);
650
+ const trimEnd = pathname.length - QDATA_JSON_LEN + (globalThis.__NO_TRAILING_SLASH__ ? 0 : 1);
667
651
  pathname = pathname.slice(0, trimEnd);
668
652
  if (pathname === "") {
669
653
  pathname = "/";
@@ -683,7 +667,6 @@ var RequestEvQwikSerializer = Symbol("RequestEvQwikSerializer");
683
667
  var RequestEvLoaderSerializationStrategyMap = Symbol(
684
668
  "RequestEvLoaderSerializationStrategyMap"
685
669
  );
686
- var RequestEvTrailingSlash = Symbol("RequestEvTrailingSlash");
687
670
  var RequestRouteName = "@routeName";
688
671
  var RequestEvSharedActionId = "@actionId";
689
672
  var RequestEvSharedActionFormData = "@actionFormData";
@@ -691,7 +674,7 @@ var RequestEvSharedNonce = "@nonce";
691
674
  var RequestEvIsRewrite = "@rewrite";
692
675
  var RequestEvShareServerTiming = "@serverTiming";
693
676
  var RequestEvShareQData = "qData";
694
- function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trailingSlash, basePathname, qwikSerializer, resolved) {
677
+ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, basePathname, qwikSerializer, resolved) {
695
678
  const { request, platform, env } = serverRequestEv;
696
679
  const sharedMap = /* @__PURE__ */ new Map();
697
680
  const cookie = new Cookie(request.headers.get("cookie"));
@@ -699,7 +682,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
699
682
  const url = new URL(request.url);
700
683
  if (url.pathname.endsWith(QDATA_JSON)) {
701
684
  url.pathname = url.pathname.slice(0, -QDATA_JSON_LEN);
702
- if (trailingSlash && !url.pathname.endsWith("/")) {
685
+ if (!globalThis.__NO_TRAILING_SLASH__ && !url.pathname.endsWith("/")) {
703
686
  url.pathname += "/";
704
687
  }
705
688
  sharedMap.set(IsQData, true);
@@ -769,14 +752,13 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
769
752
  };
770
753
  const exit = () => {
771
754
  routeModuleIndex = ABORT_INDEX;
772
- return new AbortMessage();
755
+ return new import_request_handler2.AbortMessage();
773
756
  };
774
757
  const loaders = {};
775
758
  const requestEv = {
776
759
  [RequestEvLoaders]: loaders,
777
760
  [RequestEvLoaderSerializationStrategyMap]: /* @__PURE__ */ new Map(),
778
761
  [RequestEvMode]: serverRequestEv.mode,
779
- [RequestEvTrailingSlash]: trailingSlash,
780
762
  get [RequestEvRoute]() {
781
763
  return loadedRoute;
782
764
  },
@@ -848,7 +830,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
848
830
  },
849
831
  error: (statusCode, message) => {
850
832
  status = statusCode;
851
- return new ServerError(statusCode, message);
833
+ return new import_request_handler2.ServerError(statusCode, message);
852
834
  },
853
835
  redirect: (statusCode, url2) => {
854
836
  check();
@@ -864,7 +846,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
864
846
  headers.set("Cache-Control", "no-store");
865
847
  }
866
848
  exit();
867
- return new RedirectMessage();
849
+ return new import_request_handler2.RedirectMessage();
868
850
  },
869
851
  rewrite: (pathname) => {
870
852
  check();
@@ -872,7 +854,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, trail
872
854
  throw new Error("Rewrite does not support absolute urls");
873
855
  }
874
856
  sharedMap.set(RequestEvIsRewrite, true);
875
- return new RewriteMessage(pathname.replace(/\/+/g, "/"));
857
+ return new import_request_handler2.RewriteMessage(pathname.replace(/\/+/g, "/"));
876
858
  },
877
859
  defer: (returnData) => {
878
860
  return typeof returnData === "function" ? returnData : () => returnData;
@@ -937,9 +919,6 @@ function getRequestLoaders(requestEv) {
937
919
  function getRequestLoaderSerializationStrategyMap(requestEv) {
938
920
  return requestEv[RequestEvLoaderSerializationStrategyMap];
939
921
  }
940
- function getRequestTrailingSlash(requestEv) {
941
- return requestEv[RequestEvTrailingSlash];
942
- }
943
922
  function getRequestRoute(requestEv) {
944
923
  return requestEv[RequestEvRoute];
945
924
  }
@@ -1036,6 +1015,7 @@ function getQwikRouterServerData(requestEv) {
1036
1015
  }
1037
1016
 
1038
1017
  // packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts
1018
+ var import_request_handler3 = require("@qwik.dev/router/middleware/request-handler");
1039
1019
  var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderHandler) => {
1040
1020
  const routeLoaders = [];
1041
1021
  const routeActions = [];
@@ -1055,6 +1035,9 @@ var resolveRequestHandlers = (serverPlugins, route, method, checkOrigin, renderH
1055
1035
  const routeName = route[0 /* RouteName */];
1056
1036
  if (checkOrigin && (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE")) {
1057
1037
  requestHandlers.unshift(csrfCheckMiddleware);
1038
+ if (checkOrigin === "lax-proto") {
1039
+ requestHandlers.push(csrfLaxProtoCheckMiddleware);
1040
+ }
1058
1041
  }
1059
1042
  if (isPageRoute) {
1060
1043
  if (method === "POST" || method === "GET") {
@@ -1308,7 +1291,7 @@ async function pureServerFunction(ev) {
1308
1291
  result = await qrl.apply(ev, args);
1309
1292
  }
1310
1293
  } catch (err) {
1311
- if (err instanceof ServerError) {
1294
+ if (err instanceof import_request_handler3.ServerError) {
1312
1295
  throw ev.error(err.status, err.data);
1313
1296
  }
1314
1297
  throw ev.error(500, "Invalid request");
@@ -1342,12 +1325,11 @@ async function pureServerFunction(ev) {
1342
1325
  }
1343
1326
  }
1344
1327
  function fixTrailingSlash(ev) {
1345
- const trailingSlash = getRequestTrailingSlash(ev);
1346
1328
  const { basePathname, originalUrl, sharedMap } = ev;
1347
1329
  const { pathname, search } = originalUrl;
1348
1330
  const isQData = sharedMap.has(IsQData);
1349
1331
  if (!isQData && pathname !== basePathname && !pathname.endsWith(".html")) {
1350
- if (trailingSlash) {
1332
+ if (!globalThis.__NO_TRAILING_SLASH__) {
1351
1333
  if (!pathname.endsWith("/")) {
1352
1334
  throw ev.redirect(301 /* MovedPermanently */, pathname + "/" + search);
1353
1335
  }
@@ -1378,12 +1360,12 @@ function isLastModulePageRoute(routeModules) {
1378
1360
  const lastRouteModule = routeModules[routeModules.length - 1];
1379
1361
  return lastRouteModule && typeof lastRouteModule.default === "function";
1380
1362
  }
1381
- function getPathname(url, trailingSlash) {
1363
+ function getPathname(url) {
1382
1364
  url = new URL(url);
1383
1365
  if (url.pathname.endsWith(QDATA_JSON)) {
1384
1366
  url.pathname = url.pathname.slice(0, -QDATA_JSON.length);
1385
1367
  }
1386
- if (trailingSlash) {
1368
+ if (!globalThis.__NO_TRAILING_SLASH__) {
1387
1369
  if (!url.pathname.endsWith("/")) {
1388
1370
  url.pathname += "/";
1389
1371
  }
@@ -1396,7 +1378,13 @@ function getPathname(url, trailingSlash) {
1396
1378
  return `${url.pathname}${search ? `?${search}` : ""}${url.hash}`;
1397
1379
  }
1398
1380
  var encoder = /* @__PURE__ */ new TextEncoder();
1381
+ function csrfLaxProtoCheckMiddleware(requestEv) {
1382
+ checkCSRF(requestEv, "lax-proto");
1383
+ }
1399
1384
  function csrfCheckMiddleware(requestEv) {
1385
+ checkCSRF(requestEv);
1386
+ }
1387
+ function checkCSRF(requestEv, laxProto) {
1400
1388
  const isForm = isContentType(
1401
1389
  requestEv.request.headers,
1402
1390
  "application/x-www-form-urlencoded",
@@ -1406,7 +1394,10 @@ function csrfCheckMiddleware(requestEv) {
1406
1394
  if (isForm) {
1407
1395
  const inputOrigin = requestEv.request.headers.get("origin");
1408
1396
  const origin = requestEv.url.origin;
1409
- const forbidden = inputOrigin !== origin;
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
+ }
1410
1401
  if (forbidden) {
1411
1402
  throw requestEv.error(
1412
1403
  403,
@@ -1431,7 +1422,6 @@ function renderQwikMiddleware(render) {
1431
1422
  if (!responseHeaders.has("Content-Type")) {
1432
1423
  responseHeaders.set("Content-Type", "text/html; charset=utf-8");
1433
1424
  }
1434
- const trailingSlash = getRequestTrailingSlash(requestEv);
1435
1425
  const { readable, writable } = new TextEncoderStream();
1436
1426
  const writableStream = requestEv.getWritableStream();
1437
1427
  const pipe = readable.pipeTo(writableStream, { preventClose: true });
@@ -1453,7 +1443,7 @@ function renderQwikMiddleware(render) {
1453
1443
  loaders: getRequestLoaders(requestEv),
1454
1444
  action: requestEv.sharedMap.get(RequestEvSharedActionId),
1455
1445
  status: status !== 200 ? status : 200,
1456
- href: getPathname(requestEv.url, trailingSlash)
1446
+ href: getPathname(requestEv.url)
1457
1447
  };
1458
1448
  if (typeof result.html === "string") {
1459
1449
  await stream.write(result.html);
@@ -1475,7 +1465,7 @@ async function handleRedirect(requestEv) {
1475
1465
  try {
1476
1466
  await requestEv.next();
1477
1467
  } catch (err) {
1478
- if (!(err instanceof RedirectMessage)) {
1468
+ if (!(err instanceof import_request_handler3.RedirectMessage)) {
1479
1469
  throw err;
1480
1470
  }
1481
1471
  }
@@ -1508,7 +1498,6 @@ async function renderQData(requestEv) {
1508
1498
  }
1509
1499
  const status = requestEv.status();
1510
1500
  const redirectLocation = requestEv.headers.get("Location");
1511
- const trailingSlash = getRequestTrailingSlash(requestEv);
1512
1501
  const requestHeaders = {};
1513
1502
  requestEv.request.headers.forEach((value, key) => requestHeaders[key] = value);
1514
1503
  requestEv.headers.set("Content-Type", "application/json; charset=utf-8");
@@ -1527,12 +1516,12 @@ async function renderQData(requestEv) {
1527
1516
  // send minimal data to the client
1528
1517
  loaders,
1529
1518
  status: status !== 200 ? status : 200,
1530
- href: getPathname(requestEv.url, trailingSlash)
1519
+ href: getPathname(requestEv.url)
1531
1520
  } : {
1532
1521
  loaders,
1533
1522
  action: requestEv.sharedMap.get(RequestEvSharedActionId),
1534
1523
  status: status !== 200 ? status : 200,
1535
- href: getPathname(requestEv.url, trailingSlash),
1524
+ href: getPathname(requestEv.url),
1536
1525
  redirect: redirectLocation ?? void 0,
1537
1526
  isRewrite: requestEv.sharedMap.get(RequestEvIsRewrite)
1538
1527
  };
@@ -1576,13 +1565,21 @@ function isContentType(headers, ...types) {
1576
1565
  }
1577
1566
 
1578
1567
  // packages/qwik-router/src/middleware/request-handler/request-handler.ts
1568
+ var qwikRouterConfigActual;
1579
1569
  async function requestHandler(serverRequestEv, opts, qwikSerializer) {
1580
- const { render, qwikRouterConfig, checkOrigin } = opts;
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
+ }
1581
1578
  if (!qwikRouterConfig) {
1582
1579
  throw new Error("qwikRouterConfig is required.");
1583
1580
  }
1584
1581
  const pathname = serverRequestEv.url.pathname;
1585
- const matchPathname = getRouteMatchPathname(pathname, qwikRouterConfig.trailingSlash);
1582
+ const matchPathname = getRouteMatchPathname(pathname);
1586
1583
  const routeAndHandlers = await loadRequestHandlers(
1587
1584
  qwikRouterConfig,
1588
1585
  matchPathname,
@@ -1593,7 +1590,7 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
1593
1590
  if (routeAndHandlers) {
1594
1591
  const [route, requestHandlers] = routeAndHandlers;
1595
1592
  const rebuildRouteInfo = async (url) => {
1596
- const matchPathname2 = getRouteMatchPathname(url.pathname, qwikRouterConfig.trailingSlash);
1593
+ const matchPathname2 = getRouteMatchPathname(url.pathname);
1597
1594
  const routeAndHandlers2 = await loadRequestHandlers(
1598
1595
  qwikRouterConfig,
1599
1596
  matchPathname2,
@@ -1613,7 +1610,6 @@ async function requestHandler(serverRequestEv, opts, qwikSerializer) {
1613
1610
  route,
1614
1611
  requestHandlers,
1615
1612
  rebuildRouteInfo,
1616
- qwikRouterConfig.trailingSlash,
1617
1613
  qwikRouterConfig.basePathname,
1618
1614
  qwikSerializer
1619
1615
  );
@@ -1636,6 +1632,71 @@ async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrig
1636
1632
  return null;
1637
1633
  }
1638
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
+
1639
1700
  // packages/qwik-router/src/middleware/request-handler/polyfill.ts
1640
1701
  var _TextEncoderStream_polyfill = class {
1641
1702
  #pendingHighSurrogate = null;
@@ -1698,6 +1759,8 @@ var _TextEncoderStream_polyfill = class {
1698
1759
  ServerError,
1699
1760
  _TextEncoderStream_polyfill,
1700
1761
  getErrorHtml,
1762
+ getNotFound,
1763
+ isStaticPath,
1701
1764
  mergeHeadersCookies,
1702
1765
  requestHandler
1703
1766
  });