@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.2

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