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