@qwik.dev/router 2.0.0-beta.43 → 2.0.0-beta.45
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 +2 -1
- package/lib/adapters/bun-server/vite/index.mjs +2 -1
- package/lib/adapters/cloud-run/vite/index.mjs +2 -1
- package/lib/adapters/cloudflare-pages/vite/index.mjs +2 -1
- package/lib/adapters/deno-server/vite/index.mjs +2 -1
- package/lib/adapters/netlify-edge/vite/index.mjs +2 -1
- package/lib/adapters/node-server/vite/index.mjs +2 -1
- package/lib/adapters/shared/vite/index.mjs +35 -31
- package/lib/adapters/ssg/vite/index.mjs +4 -2
- package/lib/adapters/vercel-edge/vite/index.mjs +18 -15
- package/lib/chunks/fs.mjs +26 -23
- package/lib/chunks/head.qwik.mjs +611 -445
- package/lib/chunks/http-error.qwik.mjs +8 -7
- package/lib/chunks/pathname.mjs +9 -8
- package/lib/chunks/request-path.mjs +8 -4
- package/lib/chunks/routes.mjs +14 -14
- package/lib/chunks/server-error.mjs +11 -5
- package/lib/chunks/{url.mjs → static-file.mjs} +12 -2
- package/lib/chunks/system.mjs +18 -17
- package/lib/chunks/user-response.mjs +419 -323
- package/lib/chunks/worker-thread.mjs +87 -86
- package/lib/index.d.ts +47 -59
- package/lib/index.qwik.mjs +550 -496
- package/lib/middleware/aws-lambda/index.mjs +6 -3
- package/lib/middleware/azure-swa/index.mjs +4 -2
- package/lib/middleware/bun/index.mjs +12 -12
- package/lib/middleware/cloudflare-pages/index.mjs +19 -4
- package/lib/middleware/deno/index.mjs +12 -12
- package/lib/middleware/firebase/index.mjs +4 -2
- package/lib/middleware/netlify-edge/index.mjs +4 -2
- package/lib/middleware/node/index.mjs +16 -15
- package/lib/middleware/request-handler/index.mjs +35 -24
- package/lib/middleware/vercel-edge/index.mjs +4 -2
- package/lib/service-worker/index.mjs +2 -1
- package/lib/ssg/index.mjs +20 -16
- package/lib/vite/index.d.ts +1 -1
- package/lib/vite/index.mjs +596 -586
- package/package.json +5 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as ensureSlash } from "../../chunks/pathname.mjs";
|
|
2
2
|
import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middleware/node";
|
|
3
|
-
/** @public */
|
|
3
|
+
/** @public */
|
|
4
|
+
function createQwikRouter(opts) {
|
|
4
5
|
try {
|
|
5
6
|
const { router, staticFile } = createQwikRouter$1({
|
|
6
7
|
render: opts.render,
|
|
@@ -25,7 +26,8 @@ import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middlew
|
|
|
25
26
|
router(req, res, () => {});
|
|
26
27
|
});
|
|
27
28
|
};
|
|
28
|
-
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
29
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
30
|
+
const notFound = async (_req, _res, next) => {
|
|
29
31
|
next();
|
|
30
32
|
};
|
|
31
33
|
return {
|
|
@@ -42,5 +44,6 @@ import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middlew
|
|
|
42
44
|
/**
|
|
43
45
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
44
46
|
* @public
|
|
45
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
var createQwikCity = createQwikRouter;
|
|
46
49
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
2
2
|
import { getErrorHtml, isStaticPath, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
3
3
|
import { parseString } from "set-cookie-parser";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function createQwikRouter(opts) {
|
|
5
6
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
6
7
|
async function onAzureSwaRequest(context, req) {
|
|
7
8
|
try {
|
|
@@ -83,5 +84,6 @@ import { parseString } from "set-cookie-parser";
|
|
|
83
84
|
/**
|
|
84
85
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
85
86
|
* @public
|
|
86
|
-
*/
|
|
87
|
+
*/
|
|
88
|
+
var createQwikCity = createQwikRouter;
|
|
87
89
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MIME_TYPES, t as
|
|
1
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
2
|
import { isDev } from "@qwik.dev/core/build";
|
|
3
3
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
4
|
import { extname, join } from "node:path";
|
|
@@ -9,7 +9,8 @@ function getRequestUrl(request, opts) {
|
|
|
9
9
|
if (!origin) return url;
|
|
10
10
|
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
11
11
|
}
|
|
12
|
-
/** @public */
|
|
12
|
+
/** @public */
|
|
13
|
+
function createQwikRouter(opts) {
|
|
13
14
|
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
14
15
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
15
16
|
const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
@@ -61,16 +62,12 @@ function getRequestUrl(request, opts) {
|
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
65
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
66
|
+
const notFound = async (_request) => {
|
|
65
67
|
return null;
|
|
66
68
|
};
|
|
67
|
-
const openStaticFile = async (
|
|
68
|
-
const
|
|
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");
|
|
69
|
+
const openStaticFile = async (staticFilePath) => {
|
|
70
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
74
71
|
return {
|
|
75
72
|
filePath,
|
|
76
73
|
content: Bun.file(filePath)
|
|
@@ -80,7 +77,9 @@ function getRequestUrl(request, opts) {
|
|
|
80
77
|
try {
|
|
81
78
|
const url = getRequestUrl(request, opts);
|
|
82
79
|
if (isStaticPath(request.method || "GET", url)) {
|
|
83
|
-
const
|
|
80
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
81
|
+
if (staticFilePath === void 0) return null;
|
|
82
|
+
const { filePath, content } = await openStaticFile(staticFilePath);
|
|
84
83
|
if (!await content.exists()) return new Response("Not Found", {
|
|
85
84
|
status: 404,
|
|
86
85
|
headers: {
|
|
@@ -118,5 +117,6 @@ function getRequestUrl(request, opts) {
|
|
|
118
117
|
/**
|
|
119
118
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
120
119
|
* @public
|
|
121
|
-
*/
|
|
120
|
+
*/
|
|
121
|
+
var createQwikCity = createQwikRouter;
|
|
122
122
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isDev } from "@qwik.dev/core/build";
|
|
2
2
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
3
3
|
import { _TextEncoderStream_polyfill, getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function createQwikRouter(opts) {
|
|
5
6
|
try {
|
|
6
7
|
new globalThis.TextEncoderStream();
|
|
7
8
|
} catch {
|
|
@@ -12,7 +13,7 @@ import { _TextEncoderStream_polyfill, getErrorHtml, isStaticPath, mergeHeadersCo
|
|
|
12
13
|
try {
|
|
13
14
|
const url = new URL(request.url);
|
|
14
15
|
if (isStaticPath(request.method, url)) return env.ASSETS.fetch(request);
|
|
15
|
-
const useCache = url.hostname !== "127.0.0.1" && url.hostname !== "localhost" && url.port === "" && request.method === "GET";
|
|
16
|
+
const useCache = url.hostname !== "127.0.0.1" && url.hostname !== "localhost" && url.port === "" && request.method === "GET" && !request.headers.has("Cookie") && !request.headers.has("Authorization");
|
|
16
17
|
const cacheKey = new Request(url.href, request);
|
|
17
18
|
const cache = useCache ? await caches.open("custom:qwikrouter") : null;
|
|
18
19
|
if (cache) {
|
|
@@ -58,7 +59,7 @@ import { _TextEncoderStream_polyfill, getErrorHtml, isStaticPath, mergeHeadersCo
|
|
|
58
59
|
});
|
|
59
60
|
const response = await handledResponse.response;
|
|
60
61
|
if (response) {
|
|
61
|
-
if (response.ok && cache && response
|
|
62
|
+
if (response.ok && cache && isSharedCacheable(response)) ctx.waitUntil(cache.put(cacheKey, response.clone()));
|
|
62
63
|
return response;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -83,8 +84,22 @@ import { _TextEncoderStream_polyfill, getErrorHtml, isStaticPath, mergeHeadersCo
|
|
|
83
84
|
}
|
|
84
85
|
return onCloudflarePagesFetch;
|
|
85
86
|
}
|
|
87
|
+
var uncacheableDirectives = /* @__PURE__ */ new Set([
|
|
88
|
+
"private",
|
|
89
|
+
"no-store",
|
|
90
|
+
"no-cache"
|
|
91
|
+
]);
|
|
92
|
+
var isSharedCacheable = (response) => {
|
|
93
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
94
|
+
if (!cacheControl || response.headers.has("Set-Cookie")) return false;
|
|
95
|
+
return !cacheControl.split(",").some((value) => {
|
|
96
|
+
const directive = value.trim().split("=", 1)[0].toLowerCase();
|
|
97
|
+
return uncacheableDirectives.has(directive);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
86
100
|
/**
|
|
87
101
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
88
102
|
* @public
|
|
89
|
-
*/
|
|
103
|
+
*/
|
|
104
|
+
var createQwikCity = createQwikRouter;
|
|
90
105
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as MIME_TYPES, t as
|
|
1
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
2
|
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { isDev } from "@qwik.dev/core/build";
|
|
4
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
@@ -10,7 +10,8 @@ function getRequestUrl(request, opts, info) {
|
|
|
10
10
|
if (!origin) return url;
|
|
11
11
|
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
12
12
|
}
|
|
13
|
-
/** @public */
|
|
13
|
+
/** @public */
|
|
14
|
+
function createQwikRouter(opts) {
|
|
14
15
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
15
16
|
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
16
17
|
async function router(request, info) {
|
|
@@ -54,16 +55,12 @@ function getRequestUrl(request, opts, info) {
|
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
58
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
59
|
+
const notFound = async (_request) => {
|
|
58
60
|
return null;
|
|
59
61
|
};
|
|
60
|
-
const openStaticFile = async (
|
|
61
|
-
const
|
|
62
|
-
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
63
|
-
let filePath;
|
|
64
|
-
if (fileName.includes(".")) filePath = join(staticFolder, pathname);
|
|
65
|
-
else if (!globalThis.__NO_TRAILING_SLASH__) filePath = join(staticFolder, pathname + "index.html");
|
|
66
|
-
else filePath = join(staticFolder, pathname, "index.html");
|
|
62
|
+
const openStaticFile = async (staticFilePath) => {
|
|
63
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
67
64
|
return {
|
|
68
65
|
filePath,
|
|
69
66
|
content: await Deno.open(filePath, { read: true })
|
|
@@ -73,7 +70,9 @@ function getRequestUrl(request, opts, info) {
|
|
|
73
70
|
try {
|
|
74
71
|
const url = getRequestUrl(request, opts);
|
|
75
72
|
if (isStaticPath(request.method || "GET", url)) {
|
|
76
|
-
const
|
|
73
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
74
|
+
if (staticFilePath === void 0) return null;
|
|
75
|
+
const { filePath, content } = await openStaticFile(staticFilePath);
|
|
77
76
|
const ext = extname(filePath).replace(/^\./, "");
|
|
78
77
|
return new Response(content.readable, {
|
|
79
78
|
status: 200,
|
|
@@ -104,5 +103,6 @@ function getRequestUrl(request, opts, info) {
|
|
|
104
103
|
/**
|
|
105
104
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
106
105
|
* @public
|
|
107
|
-
*/
|
|
106
|
+
*/
|
|
107
|
+
var createQwikCity = createQwikRouter;
|
|
108
108
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middleware/node";
|
|
2
|
-
/** @public */
|
|
2
|
+
/** @public */
|
|
3
|
+
function createQwikRouter(opts) {
|
|
3
4
|
const { staticFile, router } = createQwikRouter$1({
|
|
4
5
|
render: opts.render,
|
|
5
6
|
manifest: opts.manifest,
|
|
@@ -19,5 +20,6 @@ import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middlew
|
|
|
19
20
|
/**
|
|
20
21
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
21
22
|
* @public
|
|
22
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
var createQwikCity = createQwikRouter;
|
|
23
25
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isDev } from "@qwik.dev/core/build";
|
|
2
2
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
3
3
|
import { getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function createQwikRouter(opts) {
|
|
5
6
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
6
7
|
async function onNetlifyEdgeRequest(request, context) {
|
|
7
8
|
try {
|
|
@@ -61,5 +62,6 @@ import { getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from
|
|
|
61
62
|
/**
|
|
62
63
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
63
64
|
* @public
|
|
64
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
var createQwikCity = createQwikRouter;
|
|
65
67
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { n as MIME_TYPES, t as
|
|
1
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
2
|
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
3
3
|
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
4
4
|
import { isDev } from "@qwik.dev/core";
|
|
5
5
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
6
|
import { createReadStream } from "node:fs";
|
|
7
|
-
import {
|
|
7
|
+
import { extname, join } from "node:path";
|
|
8
8
|
import { isStaticPath, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { Http2ServerRequest } from "node:http2";
|
|
11
|
+
function computeOrigin(req, opts) {
|
|
12
|
+
return opts?.getOrigin?.(req) ?? opts?.origin ?? process.env.ORIGIN ?? fallbackOrigin(req);
|
|
13
|
+
}
|
|
11
14
|
function fallbackOrigin(req) {
|
|
12
15
|
const { PROTOCOL_HEADER, HOST_HEADER } = process.env;
|
|
13
16
|
const headers = req.headers;
|
|
14
17
|
return `${PROTOCOL_HEADER && headers[PROTOCOL_HEADER] || (req.socket.encrypted || req.connection.encrypted ? "https" : "http")}://${headers[HOST_HEADER ?? (req instanceof Http2ServerRequest ? ":authority" : "host")]}`;
|
|
15
18
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
19
|
+
function getUrl(req, origin) {
|
|
20
|
+
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
18
21
|
}
|
|
19
22
|
function isClientAbortWriteError(error) {
|
|
20
23
|
if (!(error instanceof Error)) return false;
|
|
@@ -26,9 +29,6 @@ var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
|
|
|
26
29
|
function normalizeUrl(url, base) {
|
|
27
30
|
return normalizeRequestUrl(url, base);
|
|
28
31
|
}
|
|
29
|
-
function getUrl(req, origin) {
|
|
30
|
-
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
31
|
-
}
|
|
32
32
|
function createNodeResponseSink(res) {
|
|
33
33
|
let closed = res.closed || res.destroyed;
|
|
34
34
|
let responseError;
|
|
@@ -243,7 +243,8 @@ async function fromNodeHttp(url, req, res, mode, getClientConn, requestBodyLimit
|
|
|
243
243
|
locale: void 0
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
|
-
/** @public */
|
|
246
|
+
/** @public */
|
|
247
|
+
function createQwikRouter(opts) {
|
|
247
248
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
248
249
|
const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
249
250
|
const router = async (req, res, next, limits = {}) => {
|
|
@@ -275,16 +276,15 @@ async function fromNodeHttp(url, req, res, mode, getClientConn, requestBodyLimit
|
|
|
275
276
|
next(e);
|
|
276
277
|
}
|
|
277
278
|
};
|
|
278
|
-
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
279
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
280
|
+
const notFound = async (_req, _res, next) => next();
|
|
279
281
|
const staticFile = async (req, res, next) => {
|
|
280
282
|
try {
|
|
281
283
|
const url = getUrl(req, computeOrigin(req, opts));
|
|
282
284
|
if (isStaticPath(req.method || "GET", url)) {
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
else if (!globalThis.__NO_TRAILING_SLASH__) filePath = join(staticFolder, pathname + "index.html");
|
|
287
|
-
else filePath = join(staticFolder, pathname, "index.html");
|
|
285
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
286
|
+
if (staticFilePath === void 0) return next();
|
|
287
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
288
288
|
const ext = extname(filePath).replace(/^\./, "");
|
|
289
289
|
const stream = createReadStream(filePath);
|
|
290
290
|
stream.on("error", next);
|
|
@@ -309,5 +309,6 @@ async function fromNodeHttp(url, req, res, mode, getClientConn, requestBodyLimit
|
|
|
309
309
|
/**
|
|
310
310
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
311
311
|
* @public
|
|
312
|
-
*/
|
|
312
|
+
*/
|
|
313
|
+
var createQwikCity = createQwikRouter;
|
|
313
314
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Q as _asyncRequestStore, d as loadRoute } from "../../chunks/head.qwik.mjs";
|
|
2
2
|
import { c as resolveValidInternalFullPathname, l as trimInternalPathname, s as recognizeRequest, u as trimRecognizedInternalPathname } from "../../chunks/request-path.mjs";
|
|
3
3
|
import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
|
|
4
4
|
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
@@ -6,34 +6,24 @@ import { a as getStaticPathRedirect, c as clearSsrCache, d as mergeHeadersCookie
|
|
|
6
6
|
import { isDev } from "@qwik.dev/core";
|
|
7
7
|
var qwikRouterConfig;
|
|
8
8
|
async function getConfig() {
|
|
9
|
-
if (isDev)
|
|
10
|
-
|
|
9
|
+
if (isDev) {
|
|
10
|
+
const config = await import("@qwik-router-config");
|
|
11
|
+
await config.importEagerModules?.();
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
if (!qwikRouterConfig) {
|
|
15
|
+
const config = await import("@qwik-router-config");
|
|
16
|
+
await config.importEagerModules?.();
|
|
17
|
+
qwikRouterConfig = config;
|
|
18
|
+
}
|
|
11
19
|
return qwikRouterConfig;
|
|
12
20
|
}
|
|
13
|
-
function getRequestHandlerPathname(serverRequestEv, isDevRequest = isDev) {
|
|
14
|
-
const recognized = recognizeRequest(serverRequestEv.url.pathname);
|
|
15
|
-
if (!recognized) return serverRequestEv.url.pathname;
|
|
16
|
-
const loaderPathname = trimRecognizedInternalPathname(serverRequestEv.url.pathname, recognized);
|
|
17
|
-
if (recognized.type !== "@isQLoader") return loaderPathname;
|
|
18
|
-
const routePath = serverRequestEv.request.headers.get("X-Qwik-fullpath") ?? (isDevRequest ? serverRequestEv.request.headers.get("X-Qwik-route-path") : null);
|
|
19
|
-
return resolveValidInternalFullPathname(loaderPathname, routePath) ?? loaderPathname;
|
|
20
|
-
}
|
|
21
|
-
async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrigin, renderFn, serverRequestEv) {
|
|
22
|
-
const { routes, serverPlugins, cacheModules } = qwikRouterConfig;
|
|
23
|
-
const loadedRoute = await loadRoute(routes, cacheModules, pathname);
|
|
24
|
-
const loader = isDev ? devPreloadedRouteLoaders.get(serverRequestEv.request) : void 0;
|
|
25
|
-
const lastModule = loadedRoute.$mods$[loadedRoute.$mods$.length - 1];
|
|
26
|
-
if (loader && lastModule) loadedRoute.$mods$[loadedRoute.$mods$.length - 1] = Object.assign({}, lastModule, { __preloadedRouteLoader: loader });
|
|
27
|
-
return {
|
|
28
|
-
loadedRoute,
|
|
29
|
-
requestHandlers: resolveRequestHandlers(serverPlugins, loadedRoute, method, checkOrigin, renderQwikMiddleware(renderFn))
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
21
|
/**
|
|
33
22
|
* The request handler for QwikRouter. Called by every adapter.
|
|
34
23
|
*
|
|
35
24
|
* @public
|
|
36
|
-
*/
|
|
25
|
+
*/
|
|
26
|
+
async function requestHandler(serverRequestEv, opts) {
|
|
37
27
|
const { render, checkOrigin } = opts;
|
|
38
28
|
const config = await getConfig();
|
|
39
29
|
const pathname = getRequestHandlerPathname(serverRequestEv);
|
|
@@ -54,11 +44,32 @@ async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrig
|
|
|
54
44
|
if (config.fallthrough && loadedRoute.$notFound$) return null;
|
|
55
45
|
return runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, config.basePathname);
|
|
56
46
|
}
|
|
47
|
+
function getRequestHandlerPathname(serverRequestEv, isDevRequest = isDev) {
|
|
48
|
+
const recognized = recognizeRequest(serverRequestEv.url.pathname);
|
|
49
|
+
if (!recognized) return serverRequestEv.url.pathname;
|
|
50
|
+
const loaderPathname = trimRecognizedInternalPathname(serverRequestEv.url.pathname, recognized);
|
|
51
|
+
if (recognized.type !== "@isQLoader") return loaderPathname;
|
|
52
|
+
const routePath = serverRequestEv.request.headers.get("X-Qwik-fullpath") ?? (isDevRequest ? serverRequestEv.request.headers.get("X-Qwik-route-path") : null);
|
|
53
|
+
return resolveValidInternalFullPathname(loaderPathname, routePath) ?? loaderPathname;
|
|
54
|
+
}
|
|
55
|
+
async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrigin, renderFn, serverRequestEv) {
|
|
56
|
+
const { routes, serverPlugins, cacheModules } = qwikRouterConfig;
|
|
57
|
+
const loadedRoute = await loadRoute(routes, cacheModules, pathname);
|
|
58
|
+
const loader = isDev ? devPreloadedRouteLoaders.get(serverRequestEv.request) : void 0;
|
|
59
|
+
const lastModule = loadedRoute.$mods$[loadedRoute.$mods$.length - 1];
|
|
60
|
+
if (loader && lastModule) loadedRoute.$mods$[loadedRoute.$mods$.length - 1] = Object.assign({}, lastModule, { __preloadedRouteLoader: loader });
|
|
61
|
+
return {
|
|
62
|
+
loadedRoute,
|
|
63
|
+
requestHandlers: resolveRequestHandlers(serverPlugins, loadedRoute, method, checkOrigin, renderQwikMiddleware(renderFn))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
57
66
|
/**
|
|
58
67
|
* TextEncoderStream polyfill based on Node.js' implementation
|
|
59
68
|
* https://github.com/nodejs/node/blob/3f3226c8e363a5f06c1e6a37abd59b6b8c1923f1/lib/internal/webstreams/encoding.js#L38-L119
|
|
60
69
|
* (MIT License)
|
|
61
|
-
*/
|
|
70
|
+
*/
|
|
71
|
+
/** @internal */
|
|
72
|
+
var _TextEncoderStream_polyfill = class {
|
|
62
73
|
#pendingHighSurrogate = null;
|
|
63
74
|
#handle = new TextEncoder();
|
|
64
75
|
#transform = new TransformStream({
|
|
@@ -7,7 +7,8 @@ var VERCEL_COOKIE = "__vdpl";
|
|
|
7
7
|
var VERCEL_SKEW_PROTECTION_ENABLED = "VERCEL_SKEW_PROTECTION_ENABLED";
|
|
8
8
|
var VERCEL_DEPLOYMENT_ID = "VERCEL_DEPLOYMENT_ID";
|
|
9
9
|
var BASE_URL = "BASE_URL";
|
|
10
|
-
/** @public */
|
|
10
|
+
/** @public */
|
|
11
|
+
function createQwikRouter(opts) {
|
|
11
12
|
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
12
13
|
async function onVercelEdgeRequest(request) {
|
|
13
14
|
try {
|
|
@@ -80,5 +81,6 @@ var BASE_URL = "BASE_URL";
|
|
|
80
81
|
/**
|
|
81
82
|
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
82
83
|
* @public
|
|
83
|
-
*/
|
|
84
|
+
*/
|
|
85
|
+
var createQwikCity = createQwikRouter;
|
|
84
86
|
export { createQwikCity, createQwikRouter };
|
|
@@ -9,5 +9,6 @@
|
|
|
9
9
|
* If you do have custom service worker logic, you should keep the `service-worker.ts` file and
|
|
10
10
|
* `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
|
|
11
11
|
* @public
|
|
12
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
var setupServiceWorker = () => {};
|
|
13
14
|
export { setupServiceWorker };
|
package/lib/ssg/index.mjs
CHANGED
|
@@ -3,18 +3,6 @@ import { r as msToString } from "../chunks/format.mjs";
|
|
|
3
3
|
import { t as createRouteTester } from "../chunks/routes.mjs";
|
|
4
4
|
import { relative } from "node:path";
|
|
5
5
|
import { bold, dim, green, magenta, red } from "kleur/colors";
|
|
6
|
-
function validateOptions(opts) {
|
|
7
|
-
if (!opts.qwikRouterConfig) throw new Error(`Missing "qwikRouterConfig" option`);
|
|
8
|
-
let siteOrigin = opts.origin;
|
|
9
|
-
if (typeof siteOrigin !== "string" || siteOrigin.trim().length === 0) throw new Error(`Missing "origin" option`);
|
|
10
|
-
siteOrigin = siteOrigin.trim();
|
|
11
|
-
if (!/:\/\//.test(siteOrigin) || siteOrigin.startsWith("://")) throw new Error(`"origin" must start with a valid protocol, such as "https://" or "http://", received "${siteOrigin}"`);
|
|
12
|
-
try {
|
|
13
|
-
new URL(siteOrigin);
|
|
14
|
-
} catch (e) {
|
|
15
|
-
throw new Error(`Invalid "origin"`, { cause: e });
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
6
|
async function mainThread(sys) {
|
|
19
7
|
const opts = sys.getOptions();
|
|
20
8
|
validateOptions(opts);
|
|
@@ -136,7 +124,8 @@ async function mainThread(sys) {
|
|
|
136
124
|
* Traverse the route tree and call the callback for each route that has module loaders.
|
|
137
125
|
* Reconstructs the original pathname and param names from the tree path. Accumulates _L
|
|
138
126
|
* layout loaders from ancestors during traversal.
|
|
139
|
-
*/
|
|
127
|
+
*/
|
|
128
|
+
const traverseRouteTree = async (node, pathParts, basePathname, ancestorLoaders) => {
|
|
140
129
|
const currentLoaders = node._L ? [...ancestorLoaders, node._L] : ancestorLoaders;
|
|
141
130
|
const index = node._I;
|
|
142
131
|
if (index) {
|
|
@@ -203,12 +192,25 @@ async function mainThread(sys) {
|
|
|
203
192
|
}
|
|
204
193
|
});
|
|
205
194
|
}
|
|
195
|
+
function validateOptions(opts) {
|
|
196
|
+
if (!opts.qwikRouterConfig) throw new Error(`Missing "qwikRouterConfig" option`);
|
|
197
|
+
let siteOrigin = opts.origin;
|
|
198
|
+
if (typeof siteOrigin !== "string" || siteOrigin.trim().length === 0) throw new Error(`Missing "origin" option`);
|
|
199
|
+
siteOrigin = siteOrigin.trim();
|
|
200
|
+
if (!/:\/\//.test(siteOrigin) || siteOrigin.startsWith("://")) throw new Error(`"origin" must start with a valid protocol, such as "https://" or "http://", received "${siteOrigin}"`);
|
|
201
|
+
try {
|
|
202
|
+
new URL(siteOrigin);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
throw new Error(`Invalid "origin"`, { cause: e });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
206
207
|
/**
|
|
207
208
|
* Use this function when SSG should be generated from another module, such as a Vite plugin. This
|
|
208
209
|
* function's should be passed the paths of the entry module and Qwik Router Plan.
|
|
209
210
|
*
|
|
210
211
|
* @public
|
|
211
|
-
*/
|
|
212
|
+
*/
|
|
213
|
+
async function generate(opts) {
|
|
212
214
|
const { createSystem } = await import("../chunks/system.mjs");
|
|
213
215
|
return mainThread(await createSystem(opts));
|
|
214
216
|
}
|
|
@@ -219,7 +221,8 @@ async function mainThread(sys) {
|
|
|
219
221
|
* Intended to be called from a generated `run-ssg.js` wrapper that provides render/config.
|
|
220
222
|
*
|
|
221
223
|
* @public
|
|
222
|
-
*/
|
|
224
|
+
*/
|
|
225
|
+
async function runSsg(opts) {
|
|
223
226
|
try {
|
|
224
227
|
const result = await generate(opts);
|
|
225
228
|
const fs = await import("node:fs");
|
|
@@ -243,7 +246,8 @@ async function mainThread(sys) {
|
|
|
243
246
|
* @param opts - Must include `render` and `qwikRouterConfig` (imported by the worker entry). The
|
|
244
247
|
* remaining serializable options come from `workerData`.
|
|
245
248
|
* @public
|
|
246
|
-
*/
|
|
249
|
+
*/
|
|
250
|
+
async function startWorker(opts) {
|
|
247
251
|
const { workerData } = await import("node:worker_threads");
|
|
248
252
|
const mergedOpts = {
|
|
249
253
|
...workerData,
|
package/lib/vite/index.d.ts
CHANGED