@qwik.dev/router 2.0.0-beta.8 → 2.0.0-rc.0
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.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -57
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -76
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -34
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.d.ts +9 -16
- package/lib/adapters/shared/vite/index.mjs +280 -293
- package/lib/adapters/ssg/vite/index.d.ts +1 -1
- package/lib/adapters/ssg/vite/index.mjs +13 -299
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +75 -79
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +143 -0
- package/lib/chunks/head.qwik.mjs +1570 -0
- package/lib/chunks/http-error.qwik.mjs +28 -0
- package/lib/chunks/pathname.mjs +58 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +53 -0
- package/lib/chunks/route-trie-key.mjs +10 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +38 -0
- package/lib/chunks/static-file.mjs +70 -0
- package/lib/chunks/system.mjs +271 -0
- package/lib/chunks/user-response.mjs +1883 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1742 -2030
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +46 -50
- package/lib/middleware/azure-swa/index.mjs +85 -294
- package/lib/middleware/bun/index.d.ts +20 -5
- package/lib/middleware/bun/index.mjs +117 -201
- package/lib/middleware/cloudflare-pages/index.mjs +101 -101
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +103 -191
- package/lib/middleware/firebase/index.mjs +22 -31
- package/lib/middleware/netlify-edge/index.mjs +63 -80
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +298 -269
- package/lib/middleware/request-handler/index.d.ts +259 -58
- package/lib/middleware/request-handler/index.mjs +108 -1730
- package/lib/middleware/vercel-edge/index.mjs +76 -100
- package/lib/modules.d.ts +7 -4
- package/lib/service-worker/index.mjs +14 -0
- package/lib/ssg/index.d.ts +50 -26
- package/lib/ssg/index.mjs +257 -43
- package/lib/vite/index.d.ts +59 -11
- package/lib/vite/index.mjs +2533 -27535
- package/modules.d.ts +7 -4
- package/package.json +53 -70
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -130
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -338
- package/lib/adapters/ssg/vite/index.cjs +0 -339
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2085
- package/lib/middleware/node/index.cjs +0 -310
- package/lib/middleware/request-handler/index.cjs +0 -1766
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/ssg/deno.mjs +0 -8
- package/lib/ssg/index.cjs +0 -67
- package/lib/ssg/node.cjs +0 -1126
- package/lib/ssg/node.mjs +0 -1088
- package/lib/vite/index.cjs +0 -27607
|
@@ -1,287 +1,316 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { i as validateRequestBodyLimit, n as RequestBodyLimitError, t as DEFAULT_REQUEST_BODY_LIMIT } from "../../chunks/request-body-limit.mjs";
|
|
3
|
+
import { t as devPreloadedRouteLoaders } from "../../chunks/dev-preloaded-route-loader.mjs";
|
|
4
|
+
import { isDev } from "@qwik.dev/core";
|
|
3
5
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
|
-
import {
|
|
5
|
-
getNotFound,
|
|
6
|
-
isStaticPath,
|
|
7
|
-
requestHandler
|
|
8
|
-
} from "../request-handler/index.mjs";
|
|
9
6
|
import { createReadStream } from "node:fs";
|
|
10
|
-
import {
|
|
7
|
+
import { extname, join } from "node:path";
|
|
8
|
+
import { isStaticPath, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
11
9
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
|
|
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/node/http.ts
|
|
66
10
|
import { Http2ServerRequest } from "node:http2";
|
|
67
11
|
function computeOrigin(req, opts) {
|
|
68
|
-
|
|
69
|
-
return ((_a = opts == null ? void 0 : opts.getOrigin) == null ? void 0 : _a.call(opts, req)) ?? (opts == null ? void 0 : opts.origin) ?? process.env.ORIGIN ?? fallbackOrigin(req);
|
|
12
|
+
return opts?.getOrigin?.(req) ?? opts?.origin ?? process.env.ORIGIN ?? fallbackOrigin(req);
|
|
70
13
|
}
|
|
71
14
|
function fallbackOrigin(req) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const hostHeader = HOST_HEADER ?? (req instanceof Http2ServerRequest ? ":authority" : "host");
|
|
76
|
-
const host = headers[hostHeader];
|
|
77
|
-
return `${protocol}://${host}`;
|
|
15
|
+
const { PROTOCOL_HEADER, HOST_HEADER } = process.env;
|
|
16
|
+
const headers = req.headers;
|
|
17
|
+
return `${PROTOCOL_HEADER && headers[PROTOCOL_HEADER] || (req.socket.encrypted || req.connection.encrypted ? "https" : "http")}://${headers[HOST_HEADER ?? (req instanceof Http2ServerRequest ? ":authority" : "host")]}`;
|
|
78
18
|
}
|
|
79
19
|
function getUrl(req, origin) {
|
|
80
|
-
|
|
20
|
+
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
81
21
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
22
|
+
function isClientAbortWriteError(error) {
|
|
23
|
+
if (!(error instanceof Error)) return false;
|
|
24
|
+
const code = error.code;
|
|
25
|
+
if (code === "EPIPE" || code === "ECONNRESET" || code === "ERR_STREAM_DESTROYED" || code === "ERR_STREAM_WRITE_AFTER_END" || code === "ERR_HTTP2_INVALID_STREAM" || code === "ERR_HTTP2_STREAM_ERROR" || code === "ERR_HTTP2_STREAM_CANCEL") return true;
|
|
26
|
+
const message = error.message;
|
|
27
|
+
if (message.includes("The stream has been destroyed") || message.includes("write after end")) return true;
|
|
28
|
+
return false;
|
|
85
29
|
}
|
|
86
30
|
var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
|
|
87
31
|
function normalizeUrl(url, base) {
|
|
88
|
-
|
|
89
|
-
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
|
|
32
|
+
return normalizeRequestUrl(url, base);
|
|
90
33
|
}
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
34
|
+
function createNodeResponseSink(res) {
|
|
35
|
+
let closed = res.closed || res.destroyed;
|
|
36
|
+
let responseError;
|
|
37
|
+
let resolveClosed;
|
|
38
|
+
const closedPromise = closed ? Promise.resolve() : new Promise((resolve) => {
|
|
39
|
+
resolveClosed = resolve;
|
|
40
|
+
res.once("close", () => {
|
|
41
|
+
closed = true;
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
res.on("error", (error) => {
|
|
46
|
+
if (responseError === void 0) responseError = error;
|
|
47
|
+
if (!closed) {
|
|
48
|
+
closed = true;
|
|
49
|
+
resolveClosed();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const shouldPropagateResponseError = () => responseError !== void 0 && !isClientAbortWriteError(responseError);
|
|
53
|
+
const write = (chunk) => {
|
|
54
|
+
if (closed || res.closed || res.destroyed) {
|
|
55
|
+
if (shouldPropagateResponseError()) return Promise.reject(responseError);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
let settled = false;
|
|
60
|
+
let onDrain;
|
|
61
|
+
const cleanupDrain = () => {
|
|
62
|
+
if (onDrain) {
|
|
63
|
+
res.off("drain", onDrain);
|
|
64
|
+
onDrain = void 0;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const finish = () => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true;
|
|
70
|
+
cleanupDrain();
|
|
71
|
+
setImmediate(resolve);
|
|
72
|
+
};
|
|
73
|
+
const finishClosed = () => {
|
|
74
|
+
closed = true;
|
|
75
|
+
finish();
|
|
76
|
+
};
|
|
77
|
+
const fail = (error) => {
|
|
78
|
+
if (settled) return;
|
|
79
|
+
settled = true;
|
|
80
|
+
closed = true;
|
|
81
|
+
cleanupDrain();
|
|
82
|
+
reject(error);
|
|
83
|
+
};
|
|
84
|
+
closedPromise.then(() => {
|
|
85
|
+
if (shouldPropagateResponseError()) {
|
|
86
|
+
fail(responseError);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
finish();
|
|
90
|
+
});
|
|
91
|
+
let ok;
|
|
92
|
+
try {
|
|
93
|
+
ok = res.write(chunk, (error) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
if (isClientAbortWriteError(error)) {
|
|
96
|
+
finishClosed();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
fail(error);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
finish();
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (isClientAbortWriteError(error)) {
|
|
106
|
+
finishClosed();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
fail(error);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (settled) return;
|
|
113
|
+
if (ok) finish();
|
|
114
|
+
else {
|
|
115
|
+
onDrain = () => {
|
|
116
|
+
onDrain = void 0;
|
|
117
|
+
finish();
|
|
118
|
+
};
|
|
119
|
+
res.once("drain", onDrain);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const close = () => {
|
|
124
|
+
if (closed || res.closed || res.destroyed) {
|
|
125
|
+
if (shouldPropagateResponseError()) return Promise.reject(responseError);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
let settled = false;
|
|
130
|
+
const finish = () => {
|
|
131
|
+
if (settled) return;
|
|
132
|
+
settled = true;
|
|
133
|
+
closed = true;
|
|
134
|
+
resolve();
|
|
135
|
+
};
|
|
136
|
+
const fail = (error) => {
|
|
137
|
+
if (settled) return;
|
|
138
|
+
settled = true;
|
|
139
|
+
closed = true;
|
|
140
|
+
reject(error);
|
|
141
|
+
};
|
|
142
|
+
closedPromise.then(() => {
|
|
143
|
+
if (shouldPropagateResponseError()) {
|
|
144
|
+
fail(responseError);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
finish();
|
|
148
|
+
});
|
|
149
|
+
res.once("finish", finish);
|
|
150
|
+
try {
|
|
151
|
+
res.end();
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (isClientAbortWriteError(error)) {
|
|
154
|
+
finish();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
fail(error);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
write,
|
|
163
|
+
close
|
|
164
|
+
};
|
|
182
165
|
}
|
|
183
|
-
|
|
184
|
-
|
|
166
|
+
async function fromNodeHttp(url, req, res, mode, getClientConn, requestBodyLimit = DEFAULT_REQUEST_BODY_LIMIT) {
|
|
167
|
+
validateRequestBodyLimit(requestBodyLimit);
|
|
168
|
+
const requestHeaders = new Headers();
|
|
169
|
+
const nodeRequestHeaders = req.headers;
|
|
170
|
+
try {
|
|
171
|
+
for (const [key, value] of Object.entries(nodeRequestHeaders)) {
|
|
172
|
+
if (invalidHeadersPattern.test(key)) continue;
|
|
173
|
+
if (typeof value === "string") requestHeaders.set(key, value);
|
|
174
|
+
else if (Array.isArray(value)) for (const v of value) requestHeaders.append(key, v);
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error(err);
|
|
178
|
+
}
|
|
179
|
+
const getRequestBody = async function* () {
|
|
180
|
+
let received = 0;
|
|
181
|
+
for await (const chunk of req) {
|
|
182
|
+
const byteLength = typeof chunk === "string" ? Buffer.byteLength(chunk) : chunk.byteLength;
|
|
183
|
+
if (byteLength > requestBodyLimit - received) {
|
|
184
|
+
req.resume();
|
|
185
|
+
throw new RequestBodyLimitError(requestBodyLimit);
|
|
186
|
+
}
|
|
187
|
+
received += byteLength;
|
|
188
|
+
yield chunk;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const body = req.method === "HEAD" || req.method === "GET" ? void 0 : getRequestBody();
|
|
192
|
+
const controller = new AbortController();
|
|
193
|
+
const abort = () => {
|
|
194
|
+
controller.abort();
|
|
195
|
+
};
|
|
196
|
+
const options = {
|
|
197
|
+
method: req.method,
|
|
198
|
+
headers: requestHeaders,
|
|
199
|
+
body,
|
|
200
|
+
signal: controller.signal,
|
|
201
|
+
duplex: "half"
|
|
202
|
+
};
|
|
203
|
+
req.on("aborted", abort);
|
|
204
|
+
req.on("error", abort);
|
|
205
|
+
res.on("close", abort);
|
|
206
|
+
res.on("error", abort);
|
|
207
|
+
return {
|
|
208
|
+
mode,
|
|
209
|
+
url,
|
|
210
|
+
request: new Request(url.href, options),
|
|
211
|
+
env: { get(key) {
|
|
212
|
+
return process.env[key];
|
|
213
|
+
} },
|
|
214
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
215
|
+
res.statusCode = status;
|
|
216
|
+
const sink = createNodeResponseSink(res);
|
|
217
|
+
try {
|
|
218
|
+
for (const [key, value] of headers) {
|
|
219
|
+
if (invalidHeadersPattern.test(key)) continue;
|
|
220
|
+
res.setHeader(key, value);
|
|
221
|
+
}
|
|
222
|
+
const cookieHeaders = cookies.headers();
|
|
223
|
+
if (cookieHeaders.length > 0) res.setHeader("Set-Cookie", cookieHeaders);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
console.error(err);
|
|
226
|
+
}
|
|
227
|
+
resolve(true);
|
|
228
|
+
return new WritableStream({
|
|
229
|
+
write(chunk) {
|
|
230
|
+
return sink.write(chunk);
|
|
231
|
+
},
|
|
232
|
+
close() {
|
|
233
|
+
return sink.close();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
getClientConn: () => {
|
|
238
|
+
return getClientConn ? getClientConn(req) : { ip: req.socket.remoteAddress };
|
|
239
|
+
},
|
|
240
|
+
platform: {
|
|
241
|
+
ssr: true,
|
|
242
|
+
incomingMessage: req,
|
|
243
|
+
node: process.versions.node
|
|
244
|
+
},
|
|
245
|
+
locale: void 0
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** @public */
|
|
185
249
|
function createQwikRouter(opts) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const origin = computeOrigin(req, opts);
|
|
247
|
-
const url = getUrl(req, origin);
|
|
248
|
-
if (isStaticPath(req.method || "GET", url)) {
|
|
249
|
-
const pathname = url.pathname;
|
|
250
|
-
let filePath;
|
|
251
|
-
if (basename(pathname).includes(".")) {
|
|
252
|
-
filePath = join(staticFolder, pathname);
|
|
253
|
-
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
254
|
-
filePath = join(staticFolder, pathname + "index.html");
|
|
255
|
-
} else {
|
|
256
|
-
filePath = join(staticFolder, pathname, "index.html");
|
|
257
|
-
}
|
|
258
|
-
const ext = extname(filePath).replace(/^\./, "");
|
|
259
|
-
const stream = createReadStream(filePath);
|
|
260
|
-
stream.on("error", next);
|
|
261
|
-
const contentType = MIME_TYPES[ext];
|
|
262
|
-
if (contentType) {
|
|
263
|
-
res.setHeader("Content-Type", contentType);
|
|
264
|
-
}
|
|
265
|
-
if ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) {
|
|
266
|
-
res.setHeader("Cache-Control", opts.static.cacheControl);
|
|
267
|
-
}
|
|
268
|
-
stream.pipe(res);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
return next();
|
|
272
|
-
} catch (e) {
|
|
273
|
-
console.error(e);
|
|
274
|
-
next(e);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
router,
|
|
279
|
-
notFound,
|
|
280
|
-
staticFile
|
|
281
|
-
};
|
|
250
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
251
|
+
const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
252
|
+
const router = async (req, res, next, limits = {}) => {
|
|
253
|
+
try {
|
|
254
|
+
const origin = computeOrigin(req, opts);
|
|
255
|
+
let requestBodyLimit = opts.requestBodyLimit;
|
|
256
|
+
if (limits?.bodyLimit !== void 0) {
|
|
257
|
+
if (requestBodyLimit === void 0) requestBodyLimit = limits.bodyLimit;
|
|
258
|
+
else requestBodyLimit = Math.min(requestBodyLimit, limits.bodyLimit);
|
|
259
|
+
}
|
|
260
|
+
const serverRequestEv = await fromNodeHttp(getUrl(req, origin), req, res, "server", opts.getClientConn, requestBodyLimit);
|
|
261
|
+
if (isDev && opts.platform) Object.assign(serverRequestEv.platform, opts.platform);
|
|
262
|
+
if (isDev) {
|
|
263
|
+
const loader = devPreloadedRouteLoaders.get(req);
|
|
264
|
+
if (loader) {
|
|
265
|
+
devPreloadedRouteLoaders.set(serverRequestEv.request, loader);
|
|
266
|
+
devPreloadedRouteLoaders.delete(req);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const handled = await requestHandler(serverRequestEv, opts);
|
|
270
|
+
if (handled) {
|
|
271
|
+
const err = await handled.completion;
|
|
272
|
+
if (handled.requestEv.headersSent) return;
|
|
273
|
+
if (err) throw err;
|
|
274
|
+
}
|
|
275
|
+
next();
|
|
276
|
+
} catch (e) {
|
|
277
|
+
console.error(e);
|
|
278
|
+
next(e);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
282
|
+
const notFound = async (_req, _res, next) => next();
|
|
283
|
+
const staticFile = async (req, res, next) => {
|
|
284
|
+
try {
|
|
285
|
+
const url = getUrl(req, computeOrigin(req, opts));
|
|
286
|
+
if (isStaticPath(req.method || "GET", url)) {
|
|
287
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
288
|
+
if (staticFilePath === void 0) return next();
|
|
289
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
290
|
+
const ext = extname(filePath).replace(/^\./, "");
|
|
291
|
+
const stream = createReadStream(filePath);
|
|
292
|
+
stream.on("error", next);
|
|
293
|
+
const contentType = MIME_TYPES[ext];
|
|
294
|
+
if (contentType) res.setHeader("Content-Type", contentType);
|
|
295
|
+
if (opts.static?.cacheControl) res.setHeader("Cache-Control", opts.static.cacheControl);
|
|
296
|
+
stream.pipe(res);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
return next();
|
|
300
|
+
} catch (e) {
|
|
301
|
+
console.error(e);
|
|
302
|
+
next(e);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return {
|
|
306
|
+
router,
|
|
307
|
+
notFound,
|
|
308
|
+
staticFile
|
|
309
|
+
};
|
|
282
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
313
|
+
* @public
|
|
314
|
+
*/
|
|
283
315
|
var createQwikCity = createQwikRouter;
|
|
284
|
-
export {
|
|
285
|
-
createQwikCity,
|
|
286
|
-
createQwikRouter
|
|
287
|
-
};
|
|
316
|
+
export { createQwikCity, createQwikRouter };
|