@qwik.dev/router 2.0.0-alpha.9 → 2.0.0-beta.10

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