@qwik.dev/router 2.0.0-beta.2 → 2.0.0-beta.21
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/adapters/static/vite.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +9 -9
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +9 -7
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +9 -7
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +9 -24
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +9 -7
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +10 -14
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +9 -7
- package/lib/adapters/shared/vite/index.d.ts +13 -19
- package/lib/adapters/shared/vite/index.mjs +107 -139
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/ssg/vite/index.mjs +18 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +9 -11
- package/lib/chunks/error-handler.mjs +57 -0
- package/lib/chunks/format-error.mjs +137 -0
- package/lib/chunks/fs.mjs +254 -0
- package/lib/{static/node.mjs → chunks/index.mjs} +361 -563
- package/lib/chunks/mime-types.mjs +52 -0
- package/lib/chunks/routing.qwik.mjs +429 -0
- package/lib/chunks/types.qwik.mjs +22 -0
- package/lib/index.d.ts +240 -60
- package/lib/index.qwik.mjs +698 -983
- package/lib/middleware/aws-lambda/index.d.ts +3 -2
- package/lib/middleware/aws-lambda/index.mjs +8 -12
- package/lib/middleware/azure-swa/index.mjs +10 -216
- package/lib/middleware/bun/index.d.ts +11 -0
- package/lib/middleware/bun/index.mjs +24 -83
- package/lib/middleware/cloudflare-pages/index.mjs +10 -22
- package/lib/middleware/deno/index.d.ts +11 -0
- package/lib/middleware/deno/index.mjs +24 -83
- package/lib/middleware/firebase/index.mjs +7 -11
- package/lib/middleware/netlify-edge/index.mjs +10 -23
- package/lib/middleware/node/index.mjs +22 -87
- package/lib/middleware/request-handler/index.d.ts +89 -70
- package/lib/middleware/request-handler/index.mjs +584 -659
- package/lib/middleware/vercel-edge/index.mjs +15 -27
- package/lib/modules.d.ts +4 -12
- package/lib/service-worker/index.mjs +4 -0
- package/lib/{static → ssg}/index.d.ts +17 -17
- package/lib/ssg/index.mjs +14 -0
- package/lib/vite/index.d.ts +32 -10
- package/lib/vite/index.mjs +1524 -26934
- package/modules.d.ts +4 -12
- package/package.json +62 -68
- package/ssg.d.ts +2 -0
- package/static.d.ts +1 -1
- 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 -129
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -378
- package/lib/adapters/static/vite/index.cjs +0 -368
- package/lib/adapters/static/vite/index.d.ts +0 -10
- package/lib/adapters/static/vite/index.mjs +0 -331
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -1947
- package/lib/middleware/node/index.cjs +0 -314
- package/lib/middleware/request-handler/index.cjs +0 -1614
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/static/deno.mjs +0 -8
- package/lib/static/index.cjs +0 -67
- package/lib/static/index.mjs +0 -48
- package/lib/static/node.cjs +0 -1124
- package/lib/vite/index.cjs +0 -27445
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -1,84 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
-
import { mergeHeadersCookies, requestHandler } from "../request-handler/index.mjs";
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { isStaticPath, getNotFound, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
import { M as MIME_TYPES } from '../../chunks/mime-types.mjs';
|
|
4
|
+
import { join, fromFileUrl, extname } from 'https://deno.land/std/path/mod.ts';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
bmp: "image/x-ms-bmp",
|
|
17
|
-
css: "text/css",
|
|
18
|
-
flv: "video/x-flv",
|
|
19
|
-
gif: "image/gif",
|
|
20
|
-
htm: "text/html",
|
|
21
|
-
html: "text/html",
|
|
22
|
-
ico: "image/x-icon",
|
|
23
|
-
jng: "image/x-jng",
|
|
24
|
-
jpeg: "image/jpeg",
|
|
25
|
-
jpg: "image/jpeg",
|
|
26
|
-
js: "application/javascript",
|
|
27
|
-
json: "application/json",
|
|
28
|
-
kar: "audio/midi",
|
|
29
|
-
m4a: "audio/x-m4a",
|
|
30
|
-
m4v: "video/x-m4v",
|
|
31
|
-
mid: "audio/midi",
|
|
32
|
-
midi: "audio/midi",
|
|
33
|
-
mng: "video/x-mng",
|
|
34
|
-
mov: "video/quicktime",
|
|
35
|
-
mp3: "audio/mpeg",
|
|
36
|
-
mp4: "video/mp4",
|
|
37
|
-
mpeg: "video/mpeg",
|
|
38
|
-
mpg: "video/mpeg",
|
|
39
|
-
ogg: "audio/ogg",
|
|
40
|
-
pdf: "application/pdf",
|
|
41
|
-
png: "image/png",
|
|
42
|
-
rar: "application/x-rar-compressed",
|
|
43
|
-
shtml: "text/html",
|
|
44
|
-
svg: "image/svg+xml",
|
|
45
|
-
svgz: "image/svg+xml",
|
|
46
|
-
tif: "image/tiff",
|
|
47
|
-
tiff: "image/tiff",
|
|
48
|
-
ts: "video/mp2t",
|
|
49
|
-
txt: "text/plain",
|
|
50
|
-
wbmp: "image/vnd.wap.wbmp",
|
|
51
|
-
webm: "video/webm",
|
|
52
|
-
webp: "image/webp",
|
|
53
|
-
wmv: "video/x-ms-wmv",
|
|
54
|
-
woff: "font/woff",
|
|
55
|
-
woff2: "font/woff2",
|
|
56
|
-
xml: "text/xml",
|
|
57
|
-
zip: "application/zip"
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// packages/qwik-router/src/middleware/deno/index.ts
|
|
61
|
-
import { extname, fromFileUrl, join } from "https://deno.land/std/path/mod.ts";
|
|
6
|
+
function getRequestUrl(request, opts, info) {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
const origin = opts.getOrigin?.(request, info) ?? Deno.env?.get?.("ORIGIN");
|
|
9
|
+
if (!origin) {
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
return new URL(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
13
|
+
}
|
|
62
14
|
function createQwikRouter(opts) {
|
|
63
|
-
var _a;
|
|
64
15
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
65
|
-
console.warn("qwikCityPlan is deprecated.
|
|
16
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
66
17
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
67
|
-
} else if (!opts.qwikRouterConfig) {
|
|
68
|
-
throw new Error("qwikRouterConfig is required.");
|
|
69
18
|
}
|
|
70
|
-
const qwikSerializer = {
|
|
71
|
-
_deserialize,
|
|
72
|
-
_serialize,
|
|
73
|
-
_verifySerializable
|
|
74
|
-
};
|
|
75
19
|
if (opts.manifest) {
|
|
76
20
|
setServerPlatform(opts.manifest);
|
|
77
21
|
}
|
|
78
|
-
const staticFolder =
|
|
22
|
+
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
79
23
|
async function router(request, info) {
|
|
80
24
|
try {
|
|
81
|
-
const url =
|
|
25
|
+
const url = getRequestUrl(request, opts, info);
|
|
82
26
|
const serverRequestEv = {
|
|
83
27
|
mode: "server",
|
|
84
28
|
locale: void 0,
|
|
@@ -104,7 +48,7 @@ function createQwikRouter(opts) {
|
|
|
104
48
|
};
|
|
105
49
|
}
|
|
106
50
|
};
|
|
107
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
51
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
108
52
|
if (handledResponse) {
|
|
109
53
|
handledResponse.completion.then((v) => {
|
|
110
54
|
if (v) {
|
|
@@ -127,8 +71,8 @@ function createQwikRouter(opts) {
|
|
|
127
71
|
}
|
|
128
72
|
const notFound = async (request) => {
|
|
129
73
|
try {
|
|
130
|
-
const url =
|
|
131
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
74
|
+
const url = getRequestUrl(request, opts);
|
|
75
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
132
76
|
return new Response(notFoundHtml, {
|
|
133
77
|
status: 404,
|
|
134
78
|
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
@@ -147,7 +91,7 @@ function createQwikRouter(opts) {
|
|
|
147
91
|
let filePath;
|
|
148
92
|
if (fileName.includes(".")) {
|
|
149
93
|
filePath = join(staticFolder, pathname);
|
|
150
|
-
} else if (
|
|
94
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
151
95
|
filePath = join(staticFolder, pathname + "index.html");
|
|
152
96
|
} else {
|
|
153
97
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -159,9 +103,8 @@ function createQwikRouter(opts) {
|
|
|
159
103
|
};
|
|
160
104
|
};
|
|
161
105
|
const staticFile = async (request) => {
|
|
162
|
-
var _a2;
|
|
163
106
|
try {
|
|
164
|
-
const url =
|
|
107
|
+
const url = getRequestUrl(request, opts);
|
|
165
108
|
if (isStaticPath(request.method || "GET", url)) {
|
|
166
109
|
const { filePath, content } = await openStaticFile(url);
|
|
167
110
|
const ext = extname(filePath).replace(/^\./, "");
|
|
@@ -169,7 +112,7 @@ function createQwikRouter(opts) {
|
|
|
169
112
|
status: 200,
|
|
170
113
|
headers: {
|
|
171
114
|
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
172
|
-
"Cache-Control":
|
|
115
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
173
116
|
}
|
|
174
117
|
});
|
|
175
118
|
}
|
|
@@ -188,8 +131,6 @@ function createQwikRouter(opts) {
|
|
|
188
131
|
staticFile
|
|
189
132
|
};
|
|
190
133
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
createQwikRouter
|
|
195
|
-
};
|
|
134
|
+
const createQwikCity = createQwikRouter;
|
|
135
|
+
|
|
136
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
|
|
2
|
+
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
4
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
5
|
-
console.warn("qwikCityPlan is deprecated.
|
|
5
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
6
6
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
-
} else if (!opts.qwikRouterConfig) {
|
|
8
|
-
throw new Error("qwikRouterConfig is required.");
|
|
9
7
|
}
|
|
10
|
-
const { staticFile, notFound, router } =
|
|
8
|
+
const { staticFile, notFound, router } = createQwikRouter$1({
|
|
11
9
|
render: opts.render,
|
|
12
10
|
manifest: opts.manifest,
|
|
13
11
|
qwikRouterConfig: opts.qwikRouterConfig,
|
|
@@ -29,8 +27,6 @@ function createQwikRouter(opts) {
|
|
|
29
27
|
};
|
|
30
28
|
return qwikApp;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
createQwikRouter
|
|
36
|
-
};
|
|
30
|
+
const createQwikCity = createQwikRouter;
|
|
31
|
+
|
|
32
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
|
|
4
|
-
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
5
|
-
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
-
import { mergeHeadersCookies, requestHandler } from "../request-handler/index.mjs";
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
|
|
7
4
|
function createQwikRouter(opts) {
|
|
8
5
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
9
|
-
console.warn("qwikCityPlan is deprecated.
|
|
6
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
10
7
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
11
|
-
} else if (!opts.qwikRouterConfig) {
|
|
12
|
-
throw new Error("qwikRouterConfig is required.");
|
|
13
8
|
}
|
|
14
|
-
const qwikSerializer = {
|
|
15
|
-
_deserialize,
|
|
16
|
-
_serialize,
|
|
17
|
-
_verifySerializable
|
|
18
|
-
};
|
|
19
9
|
if (opts.manifest) {
|
|
20
10
|
setServerPlatform(opts.manifest);
|
|
21
11
|
}
|
|
@@ -41,15 +31,14 @@ function createQwikRouter(opts) {
|
|
|
41
31
|
return writable;
|
|
42
32
|
},
|
|
43
33
|
getClientConn: () => {
|
|
44
|
-
var _a;
|
|
45
34
|
return {
|
|
46
35
|
ip: context.ip,
|
|
47
|
-
country:
|
|
36
|
+
country: context.geo.country?.code
|
|
48
37
|
};
|
|
49
38
|
},
|
|
50
39
|
platform: context
|
|
51
40
|
};
|
|
52
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
41
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
53
42
|
if (handledResponse) {
|
|
54
43
|
handledResponse.completion.then((v) => {
|
|
55
44
|
if (v) {
|
|
@@ -61,7 +50,7 @@ function createQwikRouter(opts) {
|
|
|
61
50
|
return response;
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
53
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
65
54
|
return new Response(notFoundHtml, {
|
|
66
55
|
status: 404,
|
|
67
56
|
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
@@ -76,8 +65,6 @@ function createQwikRouter(opts) {
|
|
|
76
65
|
}
|
|
77
66
|
return onNetlifyEdgeRequest;
|
|
78
67
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
createQwikRouter
|
|
83
|
-
};
|
|
68
|
+
const createQwikCity = createQwikRouter;
|
|
69
|
+
|
|
70
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,70 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { isStaticPath } from
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import { isDev } from '@qwik.dev/core';
|
|
2
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
3
|
+
import { isStaticPath, getNotFound, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
4
|
+
import { createReadStream } from 'node:fs';
|
|
5
|
+
import { join, basename, extname } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { M as MIME_TYPES } from '../../chunks/mime-types.mjs';
|
|
8
|
+
import { Http2ServerRequest } from 'node:http2';
|
|
10
9
|
|
|
11
|
-
// packages/qwik-router/src/middleware/request-handler/mime-types.ts
|
|
12
|
-
var MIME_TYPES = {
|
|
13
|
-
"3gp": "video/3gpp",
|
|
14
|
-
"3gpp": "video/3gpp",
|
|
15
|
-
asf: "video/x-ms-asf",
|
|
16
|
-
asx: "video/x-ms-asf",
|
|
17
|
-
avi: "video/x-msvideo",
|
|
18
|
-
avif: "image/avif",
|
|
19
|
-
bmp: "image/x-ms-bmp",
|
|
20
|
-
css: "text/css",
|
|
21
|
-
flv: "video/x-flv",
|
|
22
|
-
gif: "image/gif",
|
|
23
|
-
htm: "text/html",
|
|
24
|
-
html: "text/html",
|
|
25
|
-
ico: "image/x-icon",
|
|
26
|
-
jng: "image/x-jng",
|
|
27
|
-
jpeg: "image/jpeg",
|
|
28
|
-
jpg: "image/jpeg",
|
|
29
|
-
js: "application/javascript",
|
|
30
|
-
json: "application/json",
|
|
31
|
-
kar: "audio/midi",
|
|
32
|
-
m4a: "audio/x-m4a",
|
|
33
|
-
m4v: "video/x-m4v",
|
|
34
|
-
mid: "audio/midi",
|
|
35
|
-
midi: "audio/midi",
|
|
36
|
-
mng: "video/x-mng",
|
|
37
|
-
mov: "video/quicktime",
|
|
38
|
-
mp3: "audio/mpeg",
|
|
39
|
-
mp4: "video/mp4",
|
|
40
|
-
mpeg: "video/mpeg",
|
|
41
|
-
mpg: "video/mpeg",
|
|
42
|
-
ogg: "audio/ogg",
|
|
43
|
-
pdf: "application/pdf",
|
|
44
|
-
png: "image/png",
|
|
45
|
-
rar: "application/x-rar-compressed",
|
|
46
|
-
shtml: "text/html",
|
|
47
|
-
svg: "image/svg+xml",
|
|
48
|
-
svgz: "image/svg+xml",
|
|
49
|
-
tif: "image/tiff",
|
|
50
|
-
tiff: "image/tiff",
|
|
51
|
-
ts: "video/mp2t",
|
|
52
|
-
txt: "text/plain",
|
|
53
|
-
wbmp: "image/vnd.wap.wbmp",
|
|
54
|
-
webm: "video/webm",
|
|
55
|
-
webp: "image/webp",
|
|
56
|
-
wmv: "video/x-ms-wmv",
|
|
57
|
-
woff: "font/woff",
|
|
58
|
-
woff2: "font/woff2",
|
|
59
|
-
xml: "text/xml",
|
|
60
|
-
zip: "application/zip"
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// packages/qwik-router/src/middleware/node/http.ts
|
|
64
|
-
import { Http2ServerRequest } from "node:http2";
|
|
65
10
|
function computeOrigin(req, opts) {
|
|
66
|
-
|
|
67
|
-
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);
|
|
11
|
+
return opts?.getOrigin?.(req) ?? opts?.origin ?? process.env.ORIGIN ?? fallbackOrigin(req);
|
|
68
12
|
}
|
|
69
13
|
function fallbackOrigin(req) {
|
|
70
14
|
const { PROTOCOL_HEADER, HOST_HEADER } = process.env;
|
|
@@ -81,7 +25,7 @@ function isIgnoredError(message = "") {
|
|
|
81
25
|
const ignoredErrors = ["The stream has been destroyed", "write after end"];
|
|
82
26
|
return ignoredErrors.some((ignored) => message.includes(ignored));
|
|
83
27
|
}
|
|
84
|
-
|
|
28
|
+
const invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
|
|
85
29
|
function normalizeUrl(url, base) {
|
|
86
30
|
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
|
|
87
31
|
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
|
|
@@ -179,24 +123,15 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
|
179
123
|
return serverRequestEv;
|
|
180
124
|
}
|
|
181
125
|
|
|
182
|
-
// packages/qwik-router/src/middleware/node/index.ts
|
|
183
126
|
function createQwikRouter(opts) {
|
|
184
|
-
var _a;
|
|
185
127
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
186
|
-
console.warn("qwikCityPlan is deprecated.
|
|
128
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
187
129
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
188
|
-
} else if (!opts.qwikRouterConfig) {
|
|
189
|
-
throw new Error("qwikRouterConfig is required.");
|
|
190
130
|
}
|
|
191
|
-
const qwikSerializer = {
|
|
192
|
-
_deserialize,
|
|
193
|
-
_serialize,
|
|
194
|
-
_verifySerializable
|
|
195
|
-
};
|
|
196
131
|
if (opts.manifest) {
|
|
197
132
|
setServerPlatform(opts.manifest);
|
|
198
133
|
}
|
|
199
|
-
const staticFolder =
|
|
134
|
+
const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
200
135
|
const router = async (req, res, next) => {
|
|
201
136
|
try {
|
|
202
137
|
const origin = computeOrigin(req, opts);
|
|
@@ -207,7 +142,10 @@ function createQwikRouter(opts) {
|
|
|
207
142
|
"server",
|
|
208
143
|
opts.getClientConn
|
|
209
144
|
);
|
|
210
|
-
|
|
145
|
+
if (isDev && opts.platform) {
|
|
146
|
+
Object.assign(serverRequestEv.platform, opts.platform);
|
|
147
|
+
}
|
|
148
|
+
const handled = await requestHandler(serverRequestEv, opts);
|
|
211
149
|
if (handled) {
|
|
212
150
|
const err = await handled.completion;
|
|
213
151
|
if (err) {
|
|
@@ -228,7 +166,7 @@ function createQwikRouter(opts) {
|
|
|
228
166
|
if (!res.headersSent) {
|
|
229
167
|
const origin = computeOrigin(req, opts);
|
|
230
168
|
const url = getUrl(req, origin);
|
|
231
|
-
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
169
|
+
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
232
170
|
res.writeHead(404, {
|
|
233
171
|
"Content-Type": "text/html; charset=utf-8",
|
|
234
172
|
"X-Not-Found": url.pathname
|
|
@@ -241,7 +179,6 @@ function createQwikRouter(opts) {
|
|
|
241
179
|
}
|
|
242
180
|
};
|
|
243
181
|
const staticFile = async (req, res, next) => {
|
|
244
|
-
var _a2;
|
|
245
182
|
try {
|
|
246
183
|
const origin = computeOrigin(req, opts);
|
|
247
184
|
const url = getUrl(req, origin);
|
|
@@ -250,7 +187,7 @@ function createQwikRouter(opts) {
|
|
|
250
187
|
let filePath;
|
|
251
188
|
if (basename(pathname).includes(".")) {
|
|
252
189
|
filePath = join(staticFolder, pathname);
|
|
253
|
-
} else if (
|
|
190
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
254
191
|
filePath = join(staticFolder, pathname + "index.html");
|
|
255
192
|
} else {
|
|
256
193
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -262,7 +199,7 @@ function createQwikRouter(opts) {
|
|
|
262
199
|
if (contentType) {
|
|
263
200
|
res.setHeader("Content-Type", contentType);
|
|
264
201
|
}
|
|
265
|
-
if (
|
|
202
|
+
if (opts.static?.cacheControl) {
|
|
266
203
|
res.setHeader("Cache-Control", opts.static.cacheControl);
|
|
267
204
|
}
|
|
268
205
|
stream.pipe(res);
|
|
@@ -280,8 +217,6 @@ function createQwikRouter(opts) {
|
|
|
280
217
|
staticFile
|
|
281
218
|
};
|
|
282
219
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
createQwikRouter
|
|
287
|
-
};
|
|
220
|
+
const createQwikCity = createQwikRouter;
|
|
221
|
+
|
|
222
|
+
export { createQwikCity, createQwikRouter };
|