@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,140 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export { A as AbortMessage, R as RedirectMessage, S as ServerError } from '../../chunks/server-error.mjs';
|
|
9
|
-
|
|
10
|
-
let qwikRouterConfig;
|
|
1
|
+
import { Y as _asyncRequestStore, d as loadRoute } from "../../chunks/head.qwik.mjs";
|
|
2
|
+
import { c as resolveValidInternalFullPathname, l as trimInternalPathname, s as recognizeRequest, u as trimRecognizedInternalPathname } from "../../chunks/request-path.mjs";
|
|
3
|
+
import { i as RedirectMessage, r as AbortMessage, t as ServerError } from "../../chunks/server-error.mjs";
|
|
4
|
+
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
5
|
+
import { a as clearLoaderCache, c as mergeHeadersCookies, i as resolveRequestHandlers, n as getErrorHtml, o as clearSsrCache, r as renderQwikMiddleware, s as RewriteMessage, t as runQwikRouter } from "../../chunks/user-response.mjs";
|
|
6
|
+
import { isDev } from "@qwik.dev/core";
|
|
7
|
+
var qwikRouterConfig;
|
|
11
8
|
async function getConfig() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!qwikRouterConfig) {
|
|
16
|
-
qwikRouterConfig = await import('@qwik-router-config');
|
|
17
|
-
}
|
|
18
|
-
return qwikRouterConfig;
|
|
9
|
+
if (isDev) return await import("@qwik-router-config");
|
|
10
|
+
if (!qwikRouterConfig) qwikRouterConfig = await import("@qwik-router-config");
|
|
11
|
+
return qwikRouterConfig;
|
|
19
12
|
}
|
|
20
13
|
function getRequestHandlerPathname(serverRequestEv, isDevRequest = isDev) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return loaderPathname;
|
|
28
|
-
}
|
|
29
|
-
const routePath = serverRequestEv.request.headers.get(FULLPATH_HEADER) ?? (isDevRequest ? serverRequestEv.request.headers.get(ROUTE_PATH_HEADER) : null);
|
|
30
|
-
return resolveValidInternalFullPathname(loaderPathname, routePath) ?? loaderPathname;
|
|
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;
|
|
31
20
|
}
|
|
32
|
-
async function loadRequestHandlers(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const requestHandlers = resolveRequestHandlers(serverPlugins, loadedRoute, method, checkOrigin, renderQwikMiddleware(renderFn));
|
|
43
|
-
return {
|
|
44
|
-
loadedRoute,
|
|
45
|
-
requestHandlers
|
|
46
|
-
};
|
|
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
|
+
};
|
|
47
31
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The request handler for QwikRouter. Called by every adapter.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/ async function requestHandler(serverRequestEv, opts) {
|
|
37
|
+
const { render, checkOrigin } = opts;
|
|
38
|
+
const config = await getConfig();
|
|
39
|
+
const pathname = getRequestHandlerPathname(serverRequestEv);
|
|
40
|
+
if (pathname === "/.well-known" || pathname.startsWith("/.well-known/")) return null;
|
|
41
|
+
const { loadedRoute, requestHandlers } = await loadRequestHandlers(config, pathname, serverRequestEv.request.method, checkOrigin ?? true, render, serverRequestEv);
|
|
42
|
+
if (config.fallthrough && loadedRoute.$notFound$) return null;
|
|
43
|
+
const rebuildRouteInfo = async (url) => {
|
|
44
|
+
const cleanPathname = trimInternalPathname(url.pathname);
|
|
45
|
+
return loadRequestHandlers(config, cleanPathname, serverRequestEv.request.method, checkOrigin ?? true, render, serverRequestEv);
|
|
46
|
+
};
|
|
47
|
+
return runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, config.basePathname);
|
|
64
48
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if (p.startsWith("/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/")) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
return staticPaths.has(p);
|
|
49
|
+
var staticPaths = /* @__PURE__ */ new Set(["__QWIK_ROUTER_STATIC_PATHS_ARRAY__"]);
|
|
50
|
+
/**
|
|
51
|
+
* Decide whether a given request path is a static path, for optimizing file access.
|
|
52
|
+
*
|
|
53
|
+
* @internal
|
|
54
|
+
*/ function isStaticPath(method, url) {
|
|
55
|
+
if (method.toUpperCase() !== "GET") return false;
|
|
56
|
+
const p = url.pathname;
|
|
57
|
+
if (p.startsWith("/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/")) return true;
|
|
58
|
+
if (p.startsWith("/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/")) return true;
|
|
59
|
+
return staticPaths.has(p);
|
|
81
60
|
}
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export { _TextEncoderStream_polyfill, isStaticPath, requestHandler };
|
|
61
|
+
/**
|
|
62
|
+
* TextEncoderStream polyfill based on Node.js' implementation
|
|
63
|
+
* https://github.com/nodejs/node/blob/3f3226c8e363a5f06c1e6a37abd59b6b8c1923f1/lib/internal/webstreams/encoding.js#L38-L119
|
|
64
|
+
* (MIT License)
|
|
65
|
+
*/ /** @internal */ var _TextEncoderStream_polyfill = class {
|
|
66
|
+
#pendingHighSurrogate = null;
|
|
67
|
+
#handle = new TextEncoder();
|
|
68
|
+
#transform = new TransformStream({
|
|
69
|
+
transform: (chunk, controller) => {
|
|
70
|
+
chunk = String(chunk);
|
|
71
|
+
let finalChunk = "";
|
|
72
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
73
|
+
const item = chunk[i];
|
|
74
|
+
const codeUnit = item.charCodeAt(0);
|
|
75
|
+
if (this.#pendingHighSurrogate !== null) {
|
|
76
|
+
const highSurrogate = this.#pendingHighSurrogate;
|
|
77
|
+
this.#pendingHighSurrogate = null;
|
|
78
|
+
if (56320 <= codeUnit && codeUnit <= 57343) {
|
|
79
|
+
finalChunk += highSurrogate + item;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
finalChunk += "�";
|
|
83
|
+
}
|
|
84
|
+
if (55296 <= codeUnit && codeUnit <= 56319) {
|
|
85
|
+
this.#pendingHighSurrogate = item;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (56320 <= codeUnit && codeUnit <= 57343) {
|
|
89
|
+
finalChunk += "�";
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
finalChunk += item;
|
|
93
|
+
}
|
|
94
|
+
if (finalChunk) controller.enqueue(this.#handle.encode(finalChunk));
|
|
95
|
+
},
|
|
96
|
+
flush: (controller) => {
|
|
97
|
+
if (this.#pendingHighSurrogate !== null) controller.enqueue(new Uint8Array([
|
|
98
|
+
239,
|
|
99
|
+
191,
|
|
100
|
+
189
|
|
101
|
+
]));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
get encoding() {
|
|
105
|
+
return this.#handle.encoding;
|
|
106
|
+
}
|
|
107
|
+
get readable() {
|
|
108
|
+
return this.#transform.readable;
|
|
109
|
+
}
|
|
110
|
+
get writable() {
|
|
111
|
+
return this.#transform.writable;
|
|
112
|
+
}
|
|
113
|
+
get [Symbol.toStringTag]() {
|
|
114
|
+
return "TextEncoderStream";
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
export { AbortMessage, RedirectMessage, RewriteMessage, ServerError, _TextEncoderStream_polyfill, _asyncRequestStore, clearLoaderCache, clearSsrCache, getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler };
|
|
@@ -1,100 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
status: 404,
|
|
80
|
-
headers: {
|
|
81
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
82
|
-
"X-Not-Found": url.pathname
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
} catch (e) {
|
|
86
|
-
console.error(e);
|
|
87
|
-
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
88
|
-
status: 500,
|
|
89
|
-
headers: {
|
|
90
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
91
|
-
"X-Error": "vercel-edge"
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return onVercelEdgeRequest;
|
|
1
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
2
|
+
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
3
|
+
import { getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
4
|
+
var COUNTRY_HEADER_NAME = "x-vercel-ip-country";
|
|
5
|
+
var IP_HEADER_NAME = "x-real-ip";
|
|
6
|
+
var VERCEL_COOKIE = "__vdpl";
|
|
7
|
+
var VERCEL_SKEW_PROTECTION_ENABLED = "VERCEL_SKEW_PROTECTION_ENABLED";
|
|
8
|
+
var VERCEL_DEPLOYMENT_ID = "VERCEL_DEPLOYMENT_ID";
|
|
9
|
+
var BASE_URL = "BASE_URL";
|
|
10
|
+
/** @public */ function createQwikRouter(opts) {
|
|
11
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
12
|
+
async function onVercelEdgeRequest(request) {
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
if (isStaticPath(request.method, url)) return new Response(null, { headers: { "x-middleware-next": "1" } });
|
|
16
|
+
const p = (() => globalThis.process)();
|
|
17
|
+
const serverRequestEv = {
|
|
18
|
+
mode: "server",
|
|
19
|
+
locale: void 0,
|
|
20
|
+
url,
|
|
21
|
+
request,
|
|
22
|
+
env: { get(key) {
|
|
23
|
+
return p.env[key];
|
|
24
|
+
} },
|
|
25
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
26
|
+
const { readable, writable } = new TransformStream();
|
|
27
|
+
if (serverRequestEv.env.get(VERCEL_SKEW_PROTECTION_ENABLED)) {
|
|
28
|
+
const deploymentId = serverRequestEv.env.get(VERCEL_DEPLOYMENT_ID) || "";
|
|
29
|
+
const baseUrl = serverRequestEv.env.get(BASE_URL) || "/";
|
|
30
|
+
if (request.headers.has("Sec-Fetch-Dest")) cookies.set(VERCEL_COOKIE, deploymentId, {
|
|
31
|
+
path: baseUrl,
|
|
32
|
+
secure: true,
|
|
33
|
+
sameSite: true,
|
|
34
|
+
httpOnly: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
resolve(new Response(readable, {
|
|
38
|
+
status,
|
|
39
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
40
|
+
}));
|
|
41
|
+
return writable;
|
|
42
|
+
},
|
|
43
|
+
platform: {},
|
|
44
|
+
getClientConn: () => {
|
|
45
|
+
return {
|
|
46
|
+
ip: request.headers.get(IP_HEADER_NAME) ?? void 0,
|
|
47
|
+
country: request.headers.get(COUNTRY_HEADER_NAME) ?? void 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
52
|
+
if (handledResponse) {
|
|
53
|
+
handledResponse.completion.then((completion) => {
|
|
54
|
+
if (completion) console.error(completion);
|
|
55
|
+
});
|
|
56
|
+
const response = await handledResponse.response;
|
|
57
|
+
if (response) return response;
|
|
58
|
+
}
|
|
59
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
|
|
60
|
+
return new Response(notFoundHtml, {
|
|
61
|
+
status: 404,
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
64
|
+
"X-Not-Found": url.pathname
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(e);
|
|
69
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
70
|
+
status: 500,
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
73
|
+
"X-Error": "vercel-edge"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return onVercelEdgeRequest;
|
|
97
79
|
}
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
82
|
+
* @public
|
|
83
|
+
*/ var createQwikCity = createQwikRouter;
|
|
100
84
|
export { createQwikCity, createQwikRouter };
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This is no longer needed, Qwik now automatically embeds preloading logic into the
|
|
3
|
+
* application.
|
|
4
|
+
*
|
|
5
|
+
* If your service-worker.ts file contains no custom code, you should deploy to production until
|
|
6
|
+
* you're sure that all users picked up the new version, then you can remove it and also remove
|
|
7
|
+
* the `<ServiceWorkerRegister />` component from your `Root.tsx`.
|
|
8
|
+
*
|
|
9
|
+
* If you do have custom service worker logic, you should keep the `service-worker.ts` file and
|
|
10
|
+
* `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
|
|
11
|
+
* @public
|
|
12
|
+
*/ var setupServiceWorker = () => {};
|
|
4
13
|
export { setupServiceWorker };
|