@qwik.dev/router 2.0.0-beta.1 → 2.0.0-beta.11

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