@qwik.dev/router 2.0.0-beta.39 → 2.0.0-beta.40

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 (40) hide show
  1. package/lib/adapters/azure-swa/vite/index.mjs +45 -54
  2. package/lib/adapters/bun-server/vite/index.mjs +16 -22
  3. package/lib/adapters/cloud-run/vite/index.mjs +15 -19
  4. package/lib/adapters/cloudflare-pages/vite/index.mjs +46 -67
  5. package/lib/adapters/deno-server/vite/index.mjs +25 -39
  6. package/lib/adapters/netlify-edge/vite/index.mjs +50 -76
  7. package/lib/adapters/node-server/vite/index.mjs +16 -22
  8. package/lib/adapters/shared/vite/index.mjs +271 -360
  9. package/lib/adapters/ssg/vite/index.mjs +11 -15
  10. package/lib/adapters/vercel-edge/vite/index.mjs +74 -95
  11. package/lib/chunks/dev-preloaded-route-loader.mjs +2 -3
  12. package/lib/chunks/format.mjs +16 -23
  13. package/lib/chunks/fs.mjs +93 -106
  14. package/lib/chunks/head.qwik.mjs +1174 -1382
  15. package/lib/chunks/http-error.qwik.mjs +20 -28
  16. package/lib/chunks/pathname.mjs +50 -69
  17. package/lib/chunks/request-body-limit.mjs +25 -35
  18. package/lib/chunks/request-path.mjs +44 -55
  19. package/lib/chunks/routes.mjs +20 -41
  20. package/lib/chunks/server-error.mjs +15 -18
  21. package/lib/chunks/system.mjs +258 -326
  22. package/lib/chunks/url.mjs +56 -58
  23. package/lib/chunks/user-response.mjs +1616 -1804
  24. package/lib/chunks/worker-thread.mjs +254 -307
  25. package/lib/index.qwik.mjs +1637 -1918
  26. package/lib/middleware/aws-lambda/index.mjs +44 -52
  27. package/lib/middleware/azure-swa/index.mjs +85 -94
  28. package/lib/middleware/bun/index.mjs +118 -138
  29. package/lib/middleware/cloudflare-pages/index.mjs +83 -96
  30. package/lib/middleware/deno/index.mjs +104 -125
  31. package/lib/middleware/firebase/index.mjs +21 -25
  32. package/lib/middleware/netlify-edge/index.mjs +63 -71
  33. package/lib/middleware/node/index.mjs +297 -357
  34. package/lib/middleware/request-handler/index.mjs +110 -133
  35. package/lib/middleware/vercel-edge/index.mjs +82 -98
  36. package/lib/service-worker/index.mjs +12 -3
  37. package/lib/ssg/index.mjs +249 -289
  38. package/lib/vite/index.mjs +2344 -3030
  39. package/package.json +5 -5
  40. package/lib/chunks/use-functions.qwik.mjs +0 -23
@@ -1,54 +1,46 @@
1
- import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
2
- import { e as ensureSlash } from '../../chunks/pathname.mjs';
3
-
4
- function createQwikRouter(opts) {
5
- try {
6
- const { router, staticFile } = createQwikRouter$1({
7
- render: opts.render,
8
- manifest: opts.manifest,
9
- static: {
10
- cacheControl: "public, max-age=31557600"
11
- },
12
- getOrigin(req) {
13
- if (process.env.IS_OFFLINE) {
14
- return `http://${req.headers.host}`;
15
- }
16
- return null;
17
- }
18
- });
19
- const fixPath = (pathT) => {
20
- if (!globalThis.__NO_TRAILING_SLASH__) {
21
- const url = new URL(pathT, "http://aws-qwik.local");
22
- if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
23
- return pathT;
24
- }
25
- if (!url.pathname.endsWith("/")) {
26
- return ensureSlash(url.pathname) + url.search;
27
- }
28
- }
29
- return pathT;
30
- };
31
- const handle = (req, res) => {
32
- req.url = fixPath(req.url);
33
- staticFile(req, res, () => {
34
- router(req, res, () => {
35
- });
36
- });
37
- };
38
- const notFound = async (_req, _res, next) => {
39
- next();
40
- };
41
- return {
42
- fixPath,
43
- router,
44
- staticFile,
45
- notFound,
46
- handle
47
- };
48
- } catch (err) {
49
- throw new Error(err.message);
50
- }
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
+ }
51
41
  }
52
- const createQwikCity = createQwikRouter;
53
-
42
+ /**
43
+ * @deprecated Use `createQwikRouter` instead. Will be removed in V3
44
+ * @public
45
+ */ var createQwikCity = createQwikRouter;
54
46
  export { createQwikCity, createQwikRouter };
@@ -1,96 +1,87 @@
1
- import { setServerPlatform } from '@qwik.dev/core/server';
2
- import { requestHandler, isStaticPath, getErrorHtml } from '@qwik.dev/router/middleware/request-handler';
3
- import { parseString } from 'set-cookie-parser';
4
-
5
- function createQwikRouter(opts) {
6
- if (opts.manifest) {
7
- setServerPlatform(opts.manifest);
8
- }
9
- async function onAzureSwaRequest(context, req) {
10
- try {
11
- const url = new URL(req.headers["x-ms-original-url"]);
12
- const options = {
13
- method: req.method || "GET",
14
- headers: req.headers,
15
- body: req.bufferBody || req.rawBody || req.body
16
- };
17
- const serverRequestEv = {
18
- mode: "server",
19
- locale: void 0,
20
- url,
21
- platform: context,
22
- env: {
23
- get(key) {
24
- return process.env[key];
25
- }
26
- },
27
- request: new Request(url, options),
28
- getWritableStream: (status, headers, cookies, resolve) => {
29
- const chunks = [];
30
- let bodyLength = 0;
31
- const response = {
32
- status,
33
- headers: {},
34
- cookies: cookies.headers().map((header) => parseString(header))
35
- };
36
- headers.forEach((value, key) => response.headers[key] = value);
37
- return new WritableStream({
38
- write(chunk) {
39
- chunks.push(chunk.slice());
40
- bodyLength += chunk.length;
41
- },
42
- close() {
43
- const body = new Uint8Array(bodyLength);
44
- let offset = 0;
45
- for (const chunk of chunks) {
46
- body.set(chunk, offset);
47
- offset += chunk.length;
48
- }
49
- response.body = body;
50
- resolve(response);
51
- }
52
- });
53
- },
54
- getClientConn: () => {
55
- return {
56
- ip: req.headers["x-forwarded-client-Ip"],
57
- country: void 0
58
- };
59
- }
60
- };
61
- const handledResponse = await requestHandler(serverRequestEv, opts);
62
- if (handledResponse) {
63
- handledResponse.completion.then((err) => {
64
- if (err) {
65
- console.error(err);
66
- }
67
- });
68
- const response = await handledResponse.response;
69
- if (response) {
70
- return response;
71
- }
72
- }
73
- const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
74
- return {
75
- status: 404,
76
- headers: {
77
- "Content-Type": "text/html; charset=utf-8",
78
- "X-Not-Found": url.pathname
79
- },
80
- body: notFoundHtml
81
- };
82
- } catch (e) {
83
- console.error(e);
84
- return {
85
- status: 500,
86
- headers: {
87
- "Content-Type": "text/plain; charset=utf-8"
88
- }
89
- };
90
- }
91
- }
92
- return onAzureSwaRequest;
1
+ import { setServerPlatform } from "@qwik.dev/core/server";
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;
93
82
  }
94
- const createQwikCity = createQwikRouter;
95
-
83
+ /**
84
+ * @deprecated Use `createQwikRouter` instead. Will be removed in V3
85
+ * @public
86
+ */ var createQwikCity = createQwikRouter;
96
87
  export { createQwikCity, createQwikRouter };
@@ -1,142 +1,122 @@
1
- import { isDev } from '@qwik.dev/core/build';
2
- import { setServerPlatform } from '@qwik.dev/core/server';
3
- import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
4
- import { join, extname } from 'node:path';
5
- import { M as MIME_TYPES, n as normalizeRequestUrl } from '../../chunks/url.mjs';
6
-
1
+ import { n as MIME_TYPES, t as normalizeRequestUrl } from "../../chunks/url.mjs";
2
+ import { isDev } from "@qwik.dev/core/build";
3
+ import { setServerPlatform } from "@qwik.dev/core/server";
4
+ import { extname, join } from "node:path";
5
+ import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
7
6
  function getRequestUrl(request, opts) {
8
- const url = new URL(request.url);
9
- const origin = opts.getOrigin?.(request) ?? Bun.env.ORIGIN;
10
- if (!origin) {
11
- return url;
12
- }
13
- return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
7
+ const url = new URL(request.url);
8
+ const origin = opts.getOrigin?.(request) ?? Bun.env.ORIGIN;
9
+ if (!origin) return url;
10
+ return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
14
11
  }
15
- function createQwikRouter(opts) {
16
- globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
17
- if (opts.manifest) {
18
- setServerPlatform(opts.manifest);
19
- }
20
- const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
21
- async function router(request) {
22
- try {
23
- const url = getRequestUrl(request, opts);
24
- const serverRequestEv = {
25
- mode: "server",
26
- locale: void 0,
27
- url,
28
- env: {
29
- get(key) {
30
- return Bun.env[key];
31
- }
32
- },
33
- request,
34
- getWritableStream: (status, headers, cookies, resolve) => {
35
- const { readable, writable } = new TransformStream();
36
- const response = new Response(readable, {
37
- status,
38
- headers: mergeHeadersCookies(headers, cookies)
39
- });
40
- resolve(response);
41
- return writable;
42
- },
43
- platform: {
44
- ssr: true
45
- },
46
- getClientConn: () => {
47
- return opts.getClientConn ? opts.getClientConn(request) : {};
48
- }
49
- };
50
- const handledResponse = await requestHandler(serverRequestEv, opts);
51
- if (handledResponse) {
52
- handledResponse.completion.then((completion) => {
53
- if (completion) {
54
- console.error(completion);
55
- }
56
- });
57
- const response = await handledResponse.response;
58
- if (response) {
59
- const status = response.status;
60
- const location = response.headers.get("Location");
61
- const isRedirect = status >= 301 && status <= 308 && location;
62
- if (isRedirect) {
63
- return new Response(null, response);
64
- }
65
- return response;
66
- }
67
- }
68
- return null;
69
- } catch (e) {
70
- console.error(e);
71
- return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
72
- status: 500,
73
- headers: {
74
- "Content-Type": "text/plain; charset=utf-8",
75
- "X-Error": "bun-server"
76
- }
77
- });
78
- }
79
- }
80
- const notFound = async (_request) => {
81
- return null;
82
- };
83
- const openStaticFile = async (url) => {
84
- const pathname = url.pathname;
85
- const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
86
- let filePath;
87
- if (fileName.includes(".")) {
88
- filePath = join(staticFolder, pathname);
89
- } else if (!globalThis.__NO_TRAILING_SLASH__) {
90
- filePath = join(staticFolder, pathname + "index.html");
91
- } else {
92
- filePath = join(staticFolder, pathname, "index.html");
93
- }
94
- return {
95
- filePath,
96
- content: Bun.file(filePath)
97
- };
98
- };
99
- const staticFile = async (request) => {
100
- try {
101
- const url = getRequestUrl(request, opts);
102
- if (isStaticPath(request.method || "GET", url)) {
103
- const { filePath, content } = await openStaticFile(url);
104
- if (!await content.exists()) {
105
- return new Response("Not Found", {
106
- status: 404,
107
- headers: {
108
- "Content-Type": "text/plain; charset=utf-8",
109
- "X-Not-Found": url.pathname
110
- }
111
- });
112
- }
113
- const ext = extname(filePath).replace(/^\./, "");
114
- return new Response(await content.stream(), {
115
- status: 200,
116
- headers: {
117
- "content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
118
- "Cache-Control": opts.static?.cacheControl || "max-age=3600"
119
- }
120
- });
121
- }
122
- return null;
123
- } catch (e) {
124
- console.error(e);
125
- return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
126
- status: 500,
127
- headers: {
128
- "Content-Type": "text/plain; charset=utf-8",
129
- "X-Error": "bun-server"
130
- }
131
- });
132
- }
133
- };
134
- return {
135
- router,
136
- notFound,
137
- staticFile
138
- };
12
+ /** @public */ function createQwikRouter(opts) {
13
+ globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
14
+ if (opts.manifest) setServerPlatform(opts.manifest);
15
+ const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
16
+ async function router(request) {
17
+ try {
18
+ const serverRequestEv = {
19
+ mode: "server",
20
+ locale: void 0,
21
+ url: getRequestUrl(request, opts),
22
+ env: { get(key) {
23
+ return Bun.env[key];
24
+ } },
25
+ request,
26
+ getWritableStream: (status, headers, cookies, resolve) => {
27
+ const { readable, writable } = new TransformStream();
28
+ resolve(new Response(readable, {
29
+ status,
30
+ headers: mergeHeadersCookies(headers, cookies)
31
+ }));
32
+ return writable;
33
+ },
34
+ platform: { ssr: true },
35
+ getClientConn: () => {
36
+ return opts.getClientConn ? opts.getClientConn(request) : {};
37
+ }
38
+ };
39
+ const handledResponse = await requestHandler(serverRequestEv, opts);
40
+ if (handledResponse) {
41
+ handledResponse.completion.then((completion) => {
42
+ if (completion) console.error(completion);
43
+ });
44
+ const response = await handledResponse.response;
45
+ if (response) {
46
+ const status = response.status;
47
+ const location = response.headers.get("Location");
48
+ if (status >= 301 && status <= 308 && location) return new Response(null, response);
49
+ return response;
50
+ }
51
+ }
52
+ return null;
53
+ } catch (e) {
54
+ console.error(e);
55
+ return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
56
+ status: 500,
57
+ headers: {
58
+ "Content-Type": "text/plain; charset=utf-8",
59
+ "X-Error": "bun-server"
60
+ }
61
+ });
62
+ }
63
+ }
64
+ /** @deprecated `router` handles 404 responses. Will be removed in V3. */ const notFound = async (_request) => {
65
+ return null;
66
+ };
67
+ const openStaticFile = async (url) => {
68
+ const pathname = url.pathname;
69
+ const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
70
+ let filePath;
71
+ if (fileName.includes(".")) filePath = join(staticFolder, pathname);
72
+ else if (!globalThis.__NO_TRAILING_SLASH__) filePath = join(staticFolder, pathname + "index.html");
73
+ else filePath = join(staticFolder, pathname, "index.html");
74
+ return {
75
+ filePath,
76
+ content: Bun.file(filePath)
77
+ };
78
+ };
79
+ const staticFile = async (request) => {
80
+ try {
81
+ const url = getRequestUrl(request, opts);
82
+ if (isStaticPath(request.method || "GET", url)) {
83
+ const { filePath, content } = await openStaticFile(url);
84
+ if (!await content.exists()) return new Response("Not Found", {
85
+ status: 404,
86
+ headers: {
87
+ "Content-Type": "text/plain; charset=utf-8",
88
+ "X-Not-Found": url.pathname
89
+ }
90
+ });
91
+ const ext = extname(filePath).replace(/^\./, "");
92
+ return new Response(await content.stream(), {
93
+ status: 200,
94
+ headers: {
95
+ "content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
96
+ "Cache-Control": opts.static?.cacheControl || "max-age=3600"
97
+ }
98
+ });
99
+ }
100
+ return null;
101
+ } catch (e) {
102
+ console.error(e);
103
+ return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
104
+ status: 500,
105
+ headers: {
106
+ "Content-Type": "text/plain; charset=utf-8",
107
+ "X-Error": "bun-server"
108
+ }
109
+ });
110
+ }
111
+ };
112
+ return {
113
+ router,
114
+ notFound,
115
+ staticFile
116
+ };
139
117
  }
140
- const createQwikCity = createQwikRouter;
141
-
118
+ /**
119
+ * @deprecated Use `createQwikRouter` instead. Will be removed in V3
120
+ * @public
121
+ */ var createQwikCity = createQwikRouter;
142
122
  export { createQwikCity, createQwikRouter };