@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.
- package/lib/adapters/azure-swa/vite/index.mjs +45 -54
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.mjs +46 -67
- package/lib/adapters/deno-server/vite/index.mjs +25 -39
- package/lib/adapters/netlify-edge/vite/index.mjs +50 -76
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.mjs +271 -360
- package/lib/adapters/ssg/vite/index.mjs +11 -15
- package/lib/adapters/vercel-edge/vite/index.mjs +74 -95
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -3
- package/lib/chunks/format.mjs +16 -23
- package/lib/chunks/fs.mjs +93 -106
- package/lib/chunks/head.qwik.mjs +1174 -1382
- package/lib/chunks/http-error.qwik.mjs +20 -28
- package/lib/chunks/pathname.mjs +50 -69
- package/lib/chunks/request-body-limit.mjs +25 -35
- package/lib/chunks/request-path.mjs +44 -55
- package/lib/chunks/routes.mjs +20 -41
- package/lib/chunks/server-error.mjs +15 -18
- package/lib/chunks/system.mjs +258 -326
- package/lib/chunks/url.mjs +56 -58
- package/lib/chunks/user-response.mjs +1616 -1804
- package/lib/chunks/worker-thread.mjs +254 -307
- package/lib/index.qwik.mjs +1637 -1918
- package/lib/middleware/aws-lambda/index.mjs +44 -52
- package/lib/middleware/azure-swa/index.mjs +85 -94
- package/lib/middleware/bun/index.mjs +118 -138
- package/lib/middleware/cloudflare-pages/index.mjs +83 -96
- package/lib/middleware/deno/index.mjs +104 -125
- package/lib/middleware/firebase/index.mjs +21 -25
- package/lib/middleware/netlify-edge/index.mjs +63 -71
- package/lib/middleware/node/index.mjs +297 -357
- package/lib/middleware/request-handler/index.mjs +110 -133
- package/lib/middleware/vercel-edge/index.mjs +82 -98
- package/lib/service-worker/index.mjs +12 -3
- package/lib/ssg/index.mjs +249 -289
- package/lib/vite/index.mjs +2344 -3030
- package/package.json +5 -5
- package/lib/chunks/use-functions.qwik.mjs +0 -23
|
@@ -1,54 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import { parseString } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
141
|
-
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
120
|
+
* @public
|
|
121
|
+
*/ var createQwikCity = createQwikRouter;
|
|
142
122
|
export { createQwikCity, createQwikRouter };
|