@qwik.dev/router 2.0.0-beta.4 → 2.0.0-beta.41

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 (87) hide show
  1. package/adapters/static/vite.d.ts +1 -1
  2. package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
  3. package/lib/adapters/azure-swa/vite/index.mjs +44 -58
  4. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  5. package/lib/adapters/bun-server/vite/index.mjs +16 -23
  6. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  7. package/lib/adapters/cloud-run/vite/index.mjs +15 -20
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  9. package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -77
  10. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/deno-server/vite/index.mjs +25 -35
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  13. package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
  14. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  15. package/lib/adapters/node-server/vite/index.mjs +16 -23
  16. package/lib/adapters/shared/vite/index.d.ts +9 -22
  17. package/lib/adapters/shared/vite/index.mjs +280 -333
  18. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  19. package/lib/adapters/ssg/vite/index.mjs +13 -0
  20. package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
  21. package/lib/adapters/vercel-edge/vite/index.mjs +73 -80
  22. package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
  23. package/lib/chunks/format.mjs +24 -0
  24. package/lib/chunks/fs.mjs +140 -0
  25. package/lib/chunks/head.qwik.mjs +1202 -0
  26. package/lib/chunks/http-error.qwik.mjs +27 -0
  27. package/lib/chunks/pathname.mjs +57 -0
  28. package/lib/chunks/request-body-limit.mjs +27 -0
  29. package/lib/chunks/request-path.mjs +49 -0
  30. package/lib/chunks/routes.mjs +26 -0
  31. package/lib/chunks/server-error.mjs +16 -0
  32. package/lib/chunks/system.mjs +265 -0
  33. package/lib/chunks/url.mjs +59 -0
  34. package/lib/chunks/user-response.mjs +1730 -0
  35. package/lib/chunks/worker-thread.mjs +264 -0
  36. package/lib/index.d.ts +631 -174
  37. package/lib/index.qwik.mjs +1656 -1964
  38. package/lib/middleware/aws-lambda/index.d.ts +15 -16
  39. package/lib/middleware/aws-lambda/index.mjs +45 -54
  40. package/lib/middleware/azure-swa/index.mjs +85 -295
  41. package/lib/middleware/bun/index.d.ts +20 -5
  42. package/lib/middleware/bun/index.mjs +119 -205
  43. package/lib/middleware/cloudflare-pages/index.mjs +88 -105
  44. package/lib/middleware/deno/index.d.ts +22 -5
  45. package/lib/middleware/deno/index.mjs +105 -192
  46. package/lib/middleware/firebase/index.mjs +22 -35
  47. package/lib/middleware/netlify-edge/index.mjs +63 -81
  48. package/lib/middleware/node/index.d.ts +17 -5
  49. package/lib/middleware/node/index.mjs +299 -273
  50. package/lib/middleware/request-handler/index.d.ts +206 -99
  51. package/lib/middleware/request-handler/index.mjs +105 -1648
  52. package/lib/middleware/vercel-edge/index.mjs +76 -101
  53. package/lib/modules.d.ts +11 -16
  54. package/lib/service-worker/index.mjs +13 -0
  55. package/lib/{static → ssg}/index.d.ts +46 -22
  56. package/lib/ssg/index.mjs +257 -0
  57. package/lib/vite/index.d.ts +58 -10
  58. package/lib/vite/index.mjs +2471 -27446
  59. package/modules.d.ts +11 -16
  60. package/package.json +62 -70
  61. package/ssg.d.ts +2 -0
  62. package/static.d.ts +1 -1
  63. package/lib/adapters/azure-swa/vite/index.cjs +0 -96
  64. package/lib/adapters/bun-server/vite/index.cjs +0 -50
  65. package/lib/adapters/cloud-run/vite/index.cjs +0 -47
  66. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
  67. package/lib/adapters/deno-server/vite/index.cjs +0 -62
  68. package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
  69. package/lib/adapters/node-server/vite/index.cjs +0 -50
  70. package/lib/adapters/shared/vite/index.cjs +0 -378
  71. package/lib/adapters/static/vite/index.cjs +0 -368
  72. package/lib/adapters/static/vite/index.d.ts +0 -10
  73. package/lib/adapters/static/vite/index.mjs +0 -331
  74. package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
  75. package/lib/index.qwik.cjs +0 -2022
  76. package/lib/middleware/node/index.cjs +0 -314
  77. package/lib/middleware/request-handler/index.cjs +0 -1691
  78. package/lib/service-worker.cjs +0 -17
  79. package/lib/service-worker.mjs +0 -15
  80. package/lib/static/deno.mjs +0 -8
  81. package/lib/static/index.cjs +0 -67
  82. package/lib/static/index.mjs +0 -48
  83. package/lib/static/node.cjs +0 -1126
  84. package/lib/static/node.mjs +0 -1088
  85. package/lib/vite/index.cjs +0 -27525
  86. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  87. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -1,19 +1,14 @@
1
- import { Http2ServerRequest } from 'http2';
2
- import { IncomingMessage } from 'http';
3
- import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
4
- import type { QwikCityPlan } from '@qwik.dev/router';
1
+ import type { Http2ServerRequest } from 'node:http2';
2
+ import type { IncomingMessage } from 'node:http';
3
+ import type { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
5
4
  import type { QwikManifest } from '@qwik.dev/core/optimizer';
6
- import type { QwikRouterConfig } from '@qwik.dev/router';
7
5
  import type { Render } from '@qwik.dev/core/server';
8
6
  import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
9
- import { ServerResponse } from 'http';
7
+ import type { ServerResponse } from 'node:http';
10
8
 
11
9
  declare interface AwsOpt {
12
10
  render: Render;
13
11
  manifest?: QwikManifest;
14
- qwikRouterConfig: QwikRouterConfig;
15
- /** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
16
- qwikCityPlan?: QwikCityPlan;
17
12
  }
18
13
 
19
14
  /**
@@ -23,13 +18,7 @@ declare interface AwsOpt {
23
18
  export declare const createQwikCity: typeof createQwikRouter;
24
19
 
25
20
  /** @public */
26
- export declare function createQwikRouter(opts: AwsOpt): {
27
- fixPath: (pathT: string) => string;
28
- router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
29
- staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
30
- notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
31
- handle: (req: any, res: any) => void;
32
- };
21
+ export declare function createQwikRouter(opts: AwsOpt): QwikRouterAwsLambdaMiddleware;
33
22
 
34
23
  /** @public */
35
24
  export declare interface PlatformAwsLambda extends Object {
@@ -41,6 +30,16 @@ export declare interface PlatformAwsLambda extends Object {
41
30
  */
42
31
  export declare type QwikCityAwsLambdaOptions = QwikRouterAwsLambdaOptions;
43
32
 
33
+ /** @public */
34
+ export declare interface QwikRouterAwsLambdaMiddleware {
35
+ fixPath: (pathT: string) => string;
36
+ router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
37
+ staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
38
+ /** @deprecated `router` handles 404 responses. Will be removed in V3. */
39
+ notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
40
+ handle: (req: any, res: any) => void;
41
+ }
42
+
44
43
  /** @public */
45
44
  export declare interface QwikRouterAwsLambdaOptions extends ServerRenderOptions {
46
45
  }
@@ -1,55 +1,46 @@
1
- // packages/qwik-router/src/middleware/aws-lambda/index.ts
2
- import { createQwikRouter as createQwikRouterNode } from "@qwik.dev/router/middleware/node";
3
- function createQwikRouter(opts) {
4
- if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
5
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
6
- opts.qwikRouterConfig = opts.qwikCityPlan;
7
- } else if (!opts.qwikRouterConfig) {
8
- throw new Error("qwikRouterConfig is required.");
9
- }
10
- try {
11
- const { router, staticFile, notFound } = createQwikRouterNode({
12
- render: opts.render,
13
- qwikRouterConfig: opts.qwikRouterConfig,
14
- manifest: opts.manifest,
15
- static: {
16
- cacheControl: "public, max-age=31557600"
17
- },
18
- getOrigin(req) {
19
- if (process.env.IS_OFFLINE) {
20
- return `http://${req.headers.host}`;
21
- }
22
- return null;
23
- }
24
- });
25
- const fixPath = (pathT) => {
26
- if (opts.qwikRouterConfig.trailingSlash) {
27
- const url = new URL(pathT, "http://aws-qwik.local");
28
- if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
29
- return pathT;
30
- }
31
- if (!url.pathname.endsWith("/")) {
32
- return url.pathname + "/" + url.search;
33
- }
34
- }
35
- return pathT;
36
- };
37
- const handle = (req, res) => {
38
- req.url = fixPath(req.url);
39
- staticFile(req, res, () => {
40
- router(req, res, () => {
41
- notFound(req, res, () => {
42
- });
43
- });
44
- });
45
- };
46
- return { fixPath, router, staticFile, notFound, handle };
47
- } catch (err) {
48
- throw new Error(err.message);
49
- }
1
+ import { t as ensureSlash } from "../../chunks/pathname.mjs";
2
+ import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middleware/node";
3
+ /** @public */ function createQwikRouter(opts) {
4
+ try {
5
+ const { router, staticFile } = createQwikRouter$1({
6
+ render: opts.render,
7
+ manifest: opts.manifest,
8
+ static: { cacheControl: "public, max-age=31557600" },
9
+ getOrigin(req) {
10
+ if (process.env.IS_OFFLINE) return `http://${req.headers.host}`;
11
+ return null;
12
+ }
13
+ });
14
+ const fixPath = (pathT) => {
15
+ if (!globalThis.__NO_TRAILING_SLASH__) {
16
+ const url = new URL(pathT, "http://aws-qwik.local");
17
+ if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) return pathT;
18
+ if (!url.pathname.endsWith("/")) return ensureSlash(url.pathname) + url.search;
19
+ }
20
+ return pathT;
21
+ };
22
+ const handle = (req, res) => {
23
+ req.url = fixPath(req.url);
24
+ staticFile(req, res, () => {
25
+ router(req, res, () => {});
26
+ });
27
+ };
28
+ /** @deprecated `router` handles 404 responses. Will be removed in V3. */ const notFound = async (_req, _res, next) => {
29
+ next();
30
+ };
31
+ return {
32
+ fixPath,
33
+ router,
34
+ staticFile,
35
+ notFound,
36
+ handle
37
+ };
38
+ } catch (err) {
39
+ throw new Error(err.message);
40
+ }
50
41
  }
51
- var createQwikCity = createQwikRouter;
52
- export {
53
- createQwikCity,
54
- createQwikRouter
55
- };
42
+ /**
43
+ * @deprecated Use `createQwikRouter` instead. Will be removed in V3
44
+ * @public
45
+ */ var createQwikCity = createQwikRouter;
46
+ export { createQwikCity, createQwikRouter };
@@ -1,297 +1,87 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js
28
- var require_set_cookie = __commonJS({
29
- "node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js"(exports, module) {
30
- "use strict";
31
- var defaultParseOptions = {
32
- decodeValues: true,
33
- map: false,
34
- silent: false
35
- };
36
- function isNonEmptyString(str) {
37
- return typeof str === "string" && !!str.trim();
38
- }
39
- function parseString2(setCookieValue, options) {
40
- var parts = setCookieValue.split(";").filter(isNonEmptyString);
41
- var nameValuePairStr = parts.shift();
42
- var parsed = parseNameValuePair(nameValuePairStr);
43
- var name = parsed.name;
44
- var value = parsed.value;
45
- options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
46
- try {
47
- value = options.decodeValues ? decodeURIComponent(value) : value;
48
- } catch (e) {
49
- console.error(
50
- "set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.",
51
- e
52
- );
53
- }
54
- var cookie = {
55
- name,
56
- value
57
- };
58
- parts.forEach(function(part) {
59
- var sides = part.split("=");
60
- var key = sides.shift().trimLeft().toLowerCase();
61
- var value2 = sides.join("=");
62
- if (key === "expires") {
63
- cookie.expires = new Date(value2);
64
- } else if (key === "max-age") {
65
- cookie.maxAge = parseInt(value2, 10);
66
- } else if (key === "secure") {
67
- cookie.secure = true;
68
- } else if (key === "httponly") {
69
- cookie.httpOnly = true;
70
- } else if (key === "samesite") {
71
- cookie.sameSite = value2;
72
- } else {
73
- cookie[key] = value2;
74
- }
75
- });
76
- return cookie;
77
- }
78
- function parseNameValuePair(nameValuePairStr) {
79
- var name = "";
80
- var value = "";
81
- var nameValueArr = nameValuePairStr.split("=");
82
- if (nameValueArr.length > 1) {
83
- name = nameValueArr.shift();
84
- value = nameValueArr.join("=");
85
- } else {
86
- value = nameValuePairStr;
87
- }
88
- return { name, value };
89
- }
90
- function parse(input, options) {
91
- options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
92
- if (!input) {
93
- if (!options.map) {
94
- return [];
95
- } else {
96
- return {};
97
- }
98
- }
99
- if (input.headers) {
100
- if (typeof input.headers.getSetCookie === "function") {
101
- input = input.headers.getSetCookie();
102
- } else if (input.headers["set-cookie"]) {
103
- input = input.headers["set-cookie"];
104
- } else {
105
- var sch = input.headers[Object.keys(input.headers).find(function(key) {
106
- return key.toLowerCase() === "set-cookie";
107
- })];
108
- if (!sch && input.headers.cookie && !options.silent) {
109
- console.warn(
110
- "Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
111
- );
112
- }
113
- input = sch;
114
- }
115
- }
116
- if (!Array.isArray(input)) {
117
- input = [input];
118
- }
119
- options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
120
- if (!options.map) {
121
- return input.filter(isNonEmptyString).map(function(str) {
122
- return parseString2(str, options);
123
- });
124
- } else {
125
- var cookies = {};
126
- return input.filter(isNonEmptyString).reduce(function(cookies2, str) {
127
- var cookie = parseString2(str, options);
128
- cookies2[cookie.name] = cookie;
129
- return cookies2;
130
- }, cookies);
131
- }
132
- }
133
- function splitCookiesString(cookiesString) {
134
- if (Array.isArray(cookiesString)) {
135
- return cookiesString;
136
- }
137
- if (typeof cookiesString !== "string") {
138
- return [];
139
- }
140
- var cookiesStrings = [];
141
- var pos = 0;
142
- var start;
143
- var ch;
144
- var lastComma;
145
- var nextStart;
146
- var cookiesSeparatorFound;
147
- function skipWhitespace() {
148
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
149
- pos += 1;
150
- }
151
- return pos < cookiesString.length;
152
- }
153
- function notSpecialChar() {
154
- ch = cookiesString.charAt(pos);
155
- return ch !== "=" && ch !== ";" && ch !== ",";
156
- }
157
- while (pos < cookiesString.length) {
158
- start = pos;
159
- cookiesSeparatorFound = false;
160
- while (skipWhitespace()) {
161
- ch = cookiesString.charAt(pos);
162
- if (ch === ",") {
163
- lastComma = pos;
164
- pos += 1;
165
- skipWhitespace();
166
- nextStart = pos;
167
- while (pos < cookiesString.length && notSpecialChar()) {
168
- pos += 1;
169
- }
170
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
171
- cookiesSeparatorFound = true;
172
- pos = nextStart;
173
- cookiesStrings.push(cookiesString.substring(start, lastComma));
174
- start = pos;
175
- } else {
176
- pos = lastComma + 1;
177
- }
178
- } else {
179
- pos += 1;
180
- }
181
- }
182
- if (!cookiesSeparatorFound || pos >= cookiesString.length) {
183
- cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
184
- }
185
- }
186
- return cookiesStrings;
187
- }
188
- module.exports = parse;
189
- module.exports.parse = parse;
190
- module.exports.parseString = parseString2;
191
- module.exports.splitCookiesString = splitCookiesString;
192
- }
193
- });
194
-
195
- // packages/qwik-router/src/middleware/azure-swa/index.ts
196
- var import_set_cookie_parser = __toESM(require_set_cookie(), 1);
197
- import { getNotFound } from "@qwik-router-not-found-paths";
198
- import { isStaticPath } from "@qwik-router-static-paths";
199
- import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
200
1
  import { setServerPlatform } from "@qwik.dev/core/server";
201
- import { requestHandler } from "../request-handler/index.mjs";
202
- function createQwikRouter(opts) {
203
- if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
204
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
205
- opts.qwikRouterConfig = opts.qwikCityPlan;
206
- } else if (!opts.qwikRouterConfig) {
207
- throw new Error("qwikRouterConfig is required.");
208
- }
209
- const qwikSerializer = {
210
- _deserialize,
211
- _serialize,
212
- _verifySerializable
213
- };
214
- if (opts.manifest) {
215
- setServerPlatform(opts.manifest);
216
- }
217
- async function onAzureSwaRequest(context, req) {
218
- try {
219
- const url = new URL(req.headers["x-ms-original-url"]);
220
- const options = {
221
- method: req.method || "GET",
222
- headers: req.headers,
223
- body: req.bufferBody || req.rawBody || req.body
224
- };
225
- const serverRequestEv = {
226
- mode: "server",
227
- locale: void 0,
228
- url,
229
- platform: context,
230
- env: {
231
- get(key) {
232
- return process.env[key];
233
- }
234
- },
235
- request: new Request(url, options),
236
- getWritableStream: (status, headers, cookies, resolve) => {
237
- const response = {
238
- status,
239
- body: new Uint8Array(),
240
- headers: {},
241
- cookies: cookies.headers().map((header) => (0, import_set_cookie_parser.parseString)(header))
242
- };
243
- headers.forEach((value, key) => response.headers[key] = value);
244
- return new WritableStream({
245
- write(chunk) {
246
- if (response.body instanceof Uint8Array) {
247
- const newBuffer = new Uint8Array(response.body.length + chunk.length);
248
- newBuffer.set(response.body);
249
- newBuffer.set(chunk, response.body.length);
250
- response.body = newBuffer;
251
- }
252
- },
253
- close() {
254
- resolve(response);
255
- }
256
- });
257
- },
258
- getClientConn: () => {
259
- return {
260
- ip: req.headers["x-forwarded-client-Ip"],
261
- country: void 0
262
- };
263
- }
264
- };
265
- const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
266
- if (handledResponse) {
267
- handledResponse.completion.then((err) => {
268
- if (err) {
269
- console.error(err);
270
- }
271
- });
272
- const response = await handledResponse.response;
273
- if (response) {
274
- return response;
275
- }
276
- }
277
- const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
278
- return {
279
- status: 404,
280
- headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname },
281
- body: notFoundHtml
282
- };
283
- } catch (e) {
284
- console.error(e);
285
- return {
286
- status: 500,
287
- headers: { "Content-Type": "text/plain; charset=utf-8" }
288
- };
289
- }
290
- }
291
- return onAzureSwaRequest;
2
+ import { getErrorHtml, isStaticPath, requestHandler } from "@qwik.dev/router/middleware/request-handler";
3
+ import { parseString } from "set-cookie-parser";
4
+ /** @public */ function createQwikRouter(opts) {
5
+ if (opts.manifest) setServerPlatform(opts.manifest);
6
+ async function onAzureSwaRequest(context, req) {
7
+ try {
8
+ const url = new URL(req.headers["x-ms-original-url"]);
9
+ const options = {
10
+ method: req.method || "GET",
11
+ headers: req.headers,
12
+ body: req.bufferBody || req.rawBody || req.body
13
+ };
14
+ const serverRequestEv = {
15
+ mode: "server",
16
+ locale: void 0,
17
+ url,
18
+ platform: context,
19
+ env: { get(key) {
20
+ return process.env[key];
21
+ } },
22
+ request: new Request(url, options),
23
+ getWritableStream: (status, headers, cookies, resolve) => {
24
+ const chunks = [];
25
+ let bodyLength = 0;
26
+ const response = {
27
+ status,
28
+ headers: {},
29
+ cookies: cookies.headers().map((header) => parseString(header))
30
+ };
31
+ headers.forEach((value, key) => response.headers[key] = value);
32
+ return new WritableStream({
33
+ write(chunk) {
34
+ chunks.push(chunk.slice());
35
+ bodyLength += chunk.length;
36
+ },
37
+ close() {
38
+ const body = new Uint8Array(bodyLength);
39
+ let offset = 0;
40
+ for (const chunk of chunks) {
41
+ body.set(chunk, offset);
42
+ offset += chunk.length;
43
+ }
44
+ response.body = body;
45
+ resolve(response);
46
+ }
47
+ });
48
+ },
49
+ getClientConn: () => {
50
+ return {
51
+ ip: req.headers["x-forwarded-client-Ip"],
52
+ country: void 0
53
+ };
54
+ }
55
+ };
56
+ const handledResponse = await requestHandler(serverRequestEv, opts);
57
+ if (handledResponse) {
58
+ handledResponse.completion.then((err) => {
59
+ if (err) console.error(err);
60
+ });
61
+ const response = await handledResponse.response;
62
+ if (response) return response;
63
+ }
64
+ const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
65
+ return {
66
+ status: 404,
67
+ headers: {
68
+ "Content-Type": "text/html; charset=utf-8",
69
+ "X-Not-Found": url.pathname
70
+ },
71
+ body: notFoundHtml
72
+ };
73
+ } catch (e) {
74
+ console.error(e);
75
+ return {
76
+ status: 500,
77
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
78
+ };
79
+ }
80
+ }
81
+ return onAzureSwaRequest;
292
82
  }
293
- var createQwikCity = createQwikRouter;
294
- export {
295
- createQwikCity,
296
- createQwikRouter
297
- };
83
+ /**
84
+ * @deprecated Use `createQwikRouter` instead. Will be removed in V3
85
+ * @public
86
+ */ var createQwikCity = createQwikRouter;
87
+ export { createQwikCity, createQwikRouter };
@@ -8,11 +8,7 @@ import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-ha
8
8
  export declare const createQwikCity: typeof createQwikRouter;
9
9
 
10
10
  /** @public */
11
- export declare function createQwikRouter(opts: QwikRouterBunOptions): {
12
- router: (request: Request) => Promise<Response | null>;
13
- notFound: (request: Request) => Promise<Response>;
14
- staticFile: (request: Request) => Promise<Response | null>;
15
- };
11
+ export declare function createQwikRouter(opts: QwikRouterBunOptions): QwikRouterBunMiddleware;
16
12
 
17
13
  /**
18
14
  * @deprecated Use `QwikRouterBunOptions` instead. Will be removed in V3
@@ -20,6 +16,14 @@ export declare function createQwikRouter(opts: QwikRouterBunOptions): {
20
16
  */
21
17
  export declare type QwikCityBunOptions = QwikRouterBunOptions;
22
18
 
19
+ /** @public */
20
+ export declare interface QwikRouterBunMiddleware {
21
+ router: (request: Request) => Promise<Response | null>;
22
+ /** @deprecated `router` handles 404 responses. Will be removed in V3. */
23
+ notFound: (request: Request) => Promise<Response>;
24
+ staticFile: (request: Request) => Promise<Response | null>;
25
+ }
26
+
23
27
  /** @public */
24
28
  export declare interface QwikRouterBunOptions extends ServerRenderOptions {
25
29
  /** Options for serving static files */
@@ -29,6 +33,17 @@ export declare interface QwikRouterBunOptions extends ServerRenderOptions {
29
33
  /** Set the Cache-Control header for all static files */
30
34
  cacheControl?: string;
31
35
  };
36
+ /**
37
+ * Provide a function that computes the origin of the server, used to resolve relative URLs and
38
+ * validate the request origin against CSRF attacks.
39
+ *
40
+ * When not specified, it defaults to the `ORIGIN` environment variable (if set).
41
+ *
42
+ * If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
43
+ * production use.
44
+ */
45
+ getOrigin?: (request: Request) => string | null;
46
+ /** Provide a function that returns a `ClientConn` for the given request. */
32
47
  getClientConn?: (request: Request) => ClientConn;
33
48
  }
34
49