@qwik.dev/router 2.0.0-beta.2 → 2.0.0-beta.21

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 (78) 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 +9 -9
  4. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  5. package/lib/adapters/bun-server/vite/index.mjs +9 -7
  6. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  7. package/lib/adapters/cloud-run/vite/index.mjs +9 -7
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  9. package/lib/adapters/cloudflare-pages/vite/index.mjs +9 -24
  10. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/deno-server/vite/index.mjs +9 -7
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  13. package/lib/adapters/netlify-edge/vite/index.mjs +10 -14
  14. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  15. package/lib/adapters/node-server/vite/index.mjs +9 -7
  16. package/lib/adapters/shared/vite/index.d.ts +13 -19
  17. package/lib/adapters/shared/vite/index.mjs +107 -139
  18. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  19. package/lib/adapters/ssg/vite/index.mjs +18 -0
  20. package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
  21. package/lib/adapters/vercel-edge/vite/index.mjs +9 -11
  22. package/lib/chunks/error-handler.mjs +57 -0
  23. package/lib/chunks/format-error.mjs +137 -0
  24. package/lib/chunks/fs.mjs +254 -0
  25. package/lib/{static/node.mjs → chunks/index.mjs} +361 -563
  26. package/lib/chunks/mime-types.mjs +52 -0
  27. package/lib/chunks/routing.qwik.mjs +429 -0
  28. package/lib/chunks/types.qwik.mjs +22 -0
  29. package/lib/index.d.ts +240 -60
  30. package/lib/index.qwik.mjs +698 -983
  31. package/lib/middleware/aws-lambda/index.d.ts +3 -2
  32. package/lib/middleware/aws-lambda/index.mjs +8 -12
  33. package/lib/middleware/azure-swa/index.mjs +10 -216
  34. package/lib/middleware/bun/index.d.ts +11 -0
  35. package/lib/middleware/bun/index.mjs +24 -83
  36. package/lib/middleware/cloudflare-pages/index.mjs +10 -22
  37. package/lib/middleware/deno/index.d.ts +11 -0
  38. package/lib/middleware/deno/index.mjs +24 -83
  39. package/lib/middleware/firebase/index.mjs +7 -11
  40. package/lib/middleware/netlify-edge/index.mjs +10 -23
  41. package/lib/middleware/node/index.mjs +22 -87
  42. package/lib/middleware/request-handler/index.d.ts +89 -70
  43. package/lib/middleware/request-handler/index.mjs +584 -659
  44. package/lib/middleware/vercel-edge/index.mjs +15 -27
  45. package/lib/modules.d.ts +4 -12
  46. package/lib/service-worker/index.mjs +4 -0
  47. package/lib/{static → ssg}/index.d.ts +17 -17
  48. package/lib/ssg/index.mjs +14 -0
  49. package/lib/vite/index.d.ts +32 -10
  50. package/lib/vite/index.mjs +1524 -26934
  51. package/modules.d.ts +4 -12
  52. package/package.json +62 -68
  53. package/ssg.d.ts +2 -0
  54. package/static.d.ts +1 -1
  55. package/lib/adapters/azure-swa/vite/index.cjs +0 -96
  56. package/lib/adapters/bun-server/vite/index.cjs +0 -50
  57. package/lib/adapters/cloud-run/vite/index.cjs +0 -47
  58. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
  59. package/lib/adapters/deno-server/vite/index.cjs +0 -62
  60. package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
  61. package/lib/adapters/node-server/vite/index.cjs +0 -50
  62. package/lib/adapters/shared/vite/index.cjs +0 -378
  63. package/lib/adapters/static/vite/index.cjs +0 -368
  64. package/lib/adapters/static/vite/index.d.ts +0 -10
  65. package/lib/adapters/static/vite/index.mjs +0 -331
  66. package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
  67. package/lib/index.qwik.cjs +0 -1947
  68. package/lib/middleware/node/index.cjs +0 -314
  69. package/lib/middleware/request-handler/index.cjs +0 -1614
  70. package/lib/service-worker.cjs +0 -17
  71. package/lib/service-worker.mjs +0 -15
  72. package/lib/static/deno.mjs +0 -8
  73. package/lib/static/index.cjs +0 -67
  74. package/lib/static/index.mjs +0 -48
  75. package/lib/static/node.cjs +0 -1124
  76. package/lib/vite/index.cjs +0 -27445
  77. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  78. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -11,8 +11,9 @@ import { ServerResponse } from 'http';
11
11
  declare interface AwsOpt {
12
12
  render: Render;
13
13
  manifest?: QwikManifest;
14
- qwikRouterConfig: QwikRouterConfig;
15
- /** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
14
+ /** @deprecated Not used */
15
+ qwikRouterConfig?: QwikRouterConfig;
16
+ /** @deprecated Not used */
16
17
  qwikCityPlan?: QwikCityPlan;
17
18
  }
18
19
 
@@ -1,14 +1,12 @@
1
- // packages/qwik-router/src/middleware/aws-lambda/index.ts
2
- import { createQwikRouter as createQwikRouterNode } from "@qwik.dev/router/middleware/node";
1
+ import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
2
+
3
3
  function createQwikRouter(opts) {
4
4
  if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
5
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
5
+ console.warn("qwikCityPlan is deprecated. Simply remove it.");
6
6
  opts.qwikRouterConfig = opts.qwikCityPlan;
7
- } else if (!opts.qwikRouterConfig) {
8
- throw new Error("qwikRouterConfig is required.");
9
7
  }
10
8
  try {
11
- const { router, staticFile, notFound } = createQwikRouterNode({
9
+ const { router, staticFile, notFound } = createQwikRouter$1({
12
10
  render: opts.render,
13
11
  qwikRouterConfig: opts.qwikRouterConfig,
14
12
  manifest: opts.manifest,
@@ -23,7 +21,7 @@ function createQwikRouter(opts) {
23
21
  }
24
22
  });
25
23
  const fixPath = (pathT) => {
26
- if (opts.qwikRouterConfig.trailingSlash) {
24
+ if (!globalThis.__NO_TRAILING_SLASH__) {
27
25
  const url = new URL(pathT, "http://aws-qwik.local");
28
26
  if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
29
27
  return pathT;
@@ -48,8 +46,6 @@ function createQwikRouter(opts) {
48
46
  throw new Error(err.message);
49
47
  }
50
48
  }
51
- var createQwikCity = createQwikRouter;
52
- export {
53
- createQwikCity,
54
- createQwikRouter
55
- };
49
+ const createQwikCity = createQwikRouter;
50
+
51
+ export { createQwikCity, createQwikRouter };
@@ -1,216 +1,12 @@
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
- });
1
+ import { setServerPlatform } from '@qwik.dev/core/server';
2
+ import { requestHandler, isStaticPath, getNotFound } from '@qwik.dev/router/middleware/request-handler';
3
+ import { parseString } from 'set-cookie-parser';
194
4
 
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
- import { setServerPlatform } from "@qwik.dev/core/server";
201
- import { requestHandler } from "../request-handler/index.mjs";
202
5
  function createQwikRouter(opts) {
203
6
  if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
204
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
7
+ console.warn("qwikCityPlan is deprecated. Simply remove it.");
205
8
  opts.qwikRouterConfig = opts.qwikCityPlan;
206
- } else if (!opts.qwikRouterConfig) {
207
- throw new Error("qwikRouterConfig is required.");
208
9
  }
209
- const qwikSerializer = {
210
- _deserialize,
211
- _serialize,
212
- _verifySerializable
213
- };
214
10
  if (opts.manifest) {
215
11
  setServerPlatform(opts.manifest);
216
12
  }
@@ -238,7 +34,7 @@ function createQwikRouter(opts) {
238
34
  status,
239
35
  body: new Uint8Array(),
240
36
  headers: {},
241
- cookies: cookies.headers().map((header) => (0, import_set_cookie_parser.parseString)(header))
37
+ cookies: cookies.headers().map((header) => parseString(header))
242
38
  };
243
39
  headers.forEach((value, key) => response.headers[key] = value);
244
40
  return new WritableStream({
@@ -262,7 +58,7 @@ function createQwikRouter(opts) {
262
58
  };
263
59
  }
264
60
  };
265
- const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
61
+ const handledResponse = await requestHandler(serverRequestEv, opts);
266
62
  if (handledResponse) {
267
63
  handledResponse.completion.then((err) => {
268
64
  if (err) {
@@ -274,7 +70,7 @@ function createQwikRouter(opts) {
274
70
  return response;
275
71
  }
276
72
  }
277
- const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
73
+ const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
278
74
  return {
279
75
  status: 404,
280
76
  headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname },
@@ -290,8 +86,6 @@ function createQwikRouter(opts) {
290
86
  }
291
87
  return onAzureSwaRequest;
292
88
  }
293
- var createQwikCity = createQwikRouter;
294
- export {
295
- createQwikCity,
296
- createQwikRouter
297
- };
89
+ const createQwikCity = createQwikRouter;
90
+
91
+ export { createQwikCity, createQwikRouter };
@@ -29,6 +29,17 @@ export declare interface QwikRouterBunOptions extends ServerRenderOptions {
29
29
  /** Set the Cache-Control header for all static files */
30
30
  cacheControl?: string;
31
31
  };
32
+ /**
33
+ * Provide a function that computes the origin of the server, used to resolve relative URLs and
34
+ * validate the request origin against CSRF attacks.
35
+ *
36
+ * When not specified, it defaults to the `ORIGIN` environment variable (if set).
37
+ *
38
+ * If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
39
+ * production use.
40
+ */
41
+ getOrigin?: (request: Request) => string | null;
42
+ /** Provide a function that returns a `ClientConn` for the given request. */
32
43
  getClientConn?: (request: Request) => ClientConn;
33
44
  }
34
45
 
@@ -1,85 +1,29 @@
1
- // packages/qwik-router/src/middleware/bun/index.ts
2
- import { getNotFound } from "@qwik-router-not-found-paths";
3
- import { isStaticPath } from "@qwik-router-static-paths";
4
- import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
5
- import { setServerPlatform } from "@qwik.dev/core/server";
6
- import {
7
- _TextEncoderStream_polyfill,
8
- mergeHeadersCookies,
9
- requestHandler
10
- } from "../request-handler/index.mjs";
11
- import { extname, join } from "node:path";
1
+ import { setServerPlatform } from '@qwik.dev/core/server';
2
+ import { _TextEncoderStream_polyfill, isStaticPath, getNotFound, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
3
+ import { join, extname } from 'node:path';
4
+ import { M as MIME_TYPES } from '../../chunks/mime-types.mjs';
12
5
 
13
- // packages/qwik-router/src/middleware/request-handler/mime-types.ts
14
- var MIME_TYPES = {
15
- "3gp": "video/3gpp",
16
- "3gpp": "video/3gpp",
17
- asf: "video/x-ms-asf",
18
- asx: "video/x-ms-asf",
19
- avi: "video/x-msvideo",
20
- avif: "image/avif",
21
- bmp: "image/x-ms-bmp",
22
- css: "text/css",
23
- flv: "video/x-flv",
24
- gif: "image/gif",
25
- htm: "text/html",
26
- html: "text/html",
27
- ico: "image/x-icon",
28
- jng: "image/x-jng",
29
- jpeg: "image/jpeg",
30
- jpg: "image/jpeg",
31
- js: "application/javascript",
32
- json: "application/json",
33
- kar: "audio/midi",
34
- m4a: "audio/x-m4a",
35
- m4v: "video/x-m4v",
36
- mid: "audio/midi",
37
- midi: "audio/midi",
38
- mng: "video/x-mng",
39
- mov: "video/quicktime",
40
- mp3: "audio/mpeg",
41
- mp4: "video/mp4",
42
- mpeg: "video/mpeg",
43
- mpg: "video/mpeg",
44
- ogg: "audio/ogg",
45
- pdf: "application/pdf",
46
- png: "image/png",
47
- rar: "application/x-rar-compressed",
48
- shtml: "text/html",
49
- svg: "image/svg+xml",
50
- svgz: "image/svg+xml",
51
- tif: "image/tiff",
52
- tiff: "image/tiff",
53
- ts: "video/mp2t",
54
- txt: "text/plain",
55
- wbmp: "image/vnd.wap.wbmp",
56
- webm: "video/webm",
57
- webp: "image/webp",
58
- wmv: "video/x-ms-wmv",
59
- woff: "font/woff",
60
- woff2: "font/woff2",
61
- xml: "text/xml",
62
- zip: "application/zip"
63
- };
64
-
65
- // packages/qwik-router/src/middleware/bun/index.ts
6
+ function getRequestUrl(request, opts) {
7
+ const url = new URL(request.url);
8
+ const origin = opts.getOrigin?.(request) ?? Bun.env.ORIGIN;
9
+ if (!origin) {
10
+ return url;
11
+ }
12
+ return new URL(`${url.pathname}${url.search}${url.hash}`, origin);
13
+ }
66
14
  function createQwikRouter(opts) {
67
- var _a;
68
15
  if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
69
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
16
+ console.warn("qwikCityPlan is deprecated. Simply remove it.");
70
17
  opts.qwikRouterConfig = opts.qwikCityPlan;
71
- } else if (!opts.qwikRouterConfig) {
72
- throw new Error("qwikRouterConfig is required.");
73
18
  }
74
19
  globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
75
- const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
76
20
  if (opts.manifest) {
77
21
  setServerPlatform(opts.manifest);
78
22
  }
79
- const staticFolder = ((_a = opts.static) == null ? void 0 : _a.root) ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
23
+ const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
80
24
  async function router(request) {
81
25
  try {
82
- const url = new URL(request.url);
26
+ const url = getRequestUrl(request, opts);
83
27
  const serverRequestEv = {
84
28
  mode: "server",
85
29
  locale: void 0,
@@ -106,7 +50,7 @@ function createQwikRouter(opts) {
106
50
  return opts.getClientConn ? opts.getClientConn(request) : {};
107
51
  }
108
52
  };
109
- const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
53
+ const handledResponse = await requestHandler(serverRequestEv, opts);
110
54
  if (handledResponse) {
111
55
  handledResponse.completion.then((v) => {
112
56
  if (v) {
@@ -135,8 +79,8 @@ function createQwikRouter(opts) {
135
79
  }
136
80
  const notFound = async (request) => {
137
81
  try {
138
- const url = new URL(request.url);
139
- const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
82
+ const url = getRequestUrl(request, opts);
83
+ const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
140
84
  return new Response(notFoundHtml, {
141
85
  status: 404,
142
86
  headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
@@ -155,7 +99,7 @@ function createQwikRouter(opts) {
155
99
  let filePath;
156
100
  if (fileName.includes(".")) {
157
101
  filePath = join(staticFolder, pathname);
158
- } else if (opts.qwikRouterConfig.trailingSlash) {
102
+ } else if (!globalThis.__NO_TRAILING_SLASH__) {
159
103
  filePath = join(staticFolder, pathname + "index.html");
160
104
  } else {
161
105
  filePath = join(staticFolder, pathname, "index.html");
@@ -166,9 +110,8 @@ function createQwikRouter(opts) {
166
110
  };
167
111
  };
168
112
  const staticFile = async (request) => {
169
- var _a2;
170
113
  try {
171
- const url = new URL(request.url);
114
+ const url = getRequestUrl(request, opts);
172
115
  if (isStaticPath(request.method || "GET", url)) {
173
116
  const { filePath, content } = await openStaticFile(url);
174
117
  if (!await content.exists()) {
@@ -182,7 +125,7 @@ function createQwikRouter(opts) {
182
125
  status: 200,
183
126
  headers: {
184
127
  "content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
185
- "Cache-Control": ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) || "max-age=3600"
128
+ "Cache-Control": opts.static?.cacheControl || "max-age=3600"
186
129
  }
187
130
  });
188
131
  }
@@ -201,8 +144,6 @@ function createQwikRouter(opts) {
201
144
  staticFile
202
145
  };
203
146
  }
204
- var createQwikCity = createQwikRouter;
205
- export {
206
- createQwikCity,
207
- createQwikRouter
208
- };
147
+ const createQwikCity = createQwikRouter;
148
+
149
+ export { createQwikCity, createQwikRouter };
@@ -1,26 +1,16 @@
1
- // packages/qwik-router/src/middleware/cloudflare-pages/index.ts
2
- import { getNotFound } from "@qwik-router-not-found-paths";
3
- import { isStaticPath } from "@qwik-router-static-paths";
4
- import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
5
- import { setServerPlatform } from "@qwik.dev/core/server";
6
- import {
7
- _TextEncoderStream_polyfill,
8
- mergeHeadersCookies,
9
- requestHandler
10
- } from "../request-handler/index.mjs";
1
+ import { setServerPlatform } from '@qwik.dev/core/server';
2
+ import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '@qwik.dev/router/middleware/request-handler';
3
+
11
4
  function createQwikRouter(opts) {
12
5
  if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
13
- console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
6
+ console.warn("qwikCityPlan is deprecated. Simply remove it.");
14
7
  opts.qwikRouterConfig = opts.qwikCityPlan;
15
- } else if (!opts.qwikRouterConfig) {
16
- throw new Error("qwikRouterConfig is required.");
17
8
  }
18
9
  try {
19
10
  new globalThis.TextEncoderStream();
20
- } catch (e) {
11
+ } catch {
21
12
  globalThis.TextEncoderStream = _TextEncoderStream_polyfill;
22
13
  }
23
- const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
24
14
  if (opts.manifest) {
25
15
  setServerPlatform(opts.manifest);
26
16
  }
@@ -70,7 +60,7 @@ function createQwikRouter(opts) {
70
60
  ctx
71
61
  }
72
62
  };
73
- const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
63
+ const handledResponse = await requestHandler(serverRequestEv, opts);
74
64
  if (handledResponse) {
75
65
  handledResponse.completion.then((v) => {
76
66
  if (v) {
@@ -85,7 +75,7 @@ function createQwikRouter(opts) {
85
75
  return response;
86
76
  }
87
77
  }
88
- const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
78
+ const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
89
79
  return new Response(notFoundHtml, {
90
80
  status: 404,
91
81
  headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
@@ -100,8 +90,6 @@ function createQwikRouter(opts) {
100
90
  }
101
91
  return onCloudflarePagesFetch;
102
92
  }
103
- var createQwikCity = createQwikRouter;
104
- export {
105
- createQwikCity,
106
- createQwikRouter
107
- };
93
+ const createQwikCity = createQwikRouter;
94
+
95
+ export { createQwikCity, createQwikRouter };
@@ -36,6 +36,17 @@ export declare interface QwikRouterDenoOptions extends ServerRenderOptions {
36
36
  /** Set the Cache-Control header for all static files */
37
37
  cacheControl?: string;
38
38
  };
39
+ /**
40
+ * Provide a function that computes the origin of the server, used to resolve relative URLs and
41
+ * validate the request origin against CSRF attacks.
42
+ *
43
+ * When not specified, it defaults to the `ORIGIN` environment variable (if set).
44
+ *
45
+ * If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
46
+ * production use.
47
+ */
48
+ getOrigin?: (request: Request, info?: ServeHandlerInfo) => string | null;
49
+ /** Provide a function that returns a `ClientConn` for the given request. */
39
50
  getClientConn?: (request: Request, info: ServeHandlerInfo) => ClientConn;
40
51
  }
41
52