@qwik.dev/router 2.0.0-beta.3 → 2.0.0-beta.31
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 +39 -44
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +6 -7
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +6 -7
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +23 -32
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +13 -9
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +22 -36
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +6 -7
- package/lib/adapters/shared/vite/index.d.ts +7 -19
- package/lib/adapters/shared/vite/index.mjs +244 -233
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/ssg/vite/index.mjs +17 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +33 -19
- package/lib/chunks/deepFreeze.qwik.mjs +18 -0
- package/lib/chunks/error-handler.mjs +57 -0
- package/lib/chunks/fs.mjs +144 -0
- package/lib/chunks/http-error.qwik.mjs +35 -0
- package/lib/chunks/not-found-wrapper.qwik.mjs +25 -0
- package/lib/chunks/pathname.mjs +105 -0
- package/lib/chunks/redirect-handler.mjs +6 -0
- package/lib/chunks/routing.qwik.mjs +821 -0
- package/lib/chunks/system.mjs +333 -0
- package/lib/chunks/url.mjs +61 -0
- package/lib/chunks/use-functions.qwik.mjs +35 -0
- package/lib/chunks/worker-thread.qwik.mjs +2573 -0
- package/lib/index.d.ts +362 -142
- package/lib/index.qwik.mjs +949 -1244
- package/lib/middleware/aws-lambda/index.d.ts +0 -5
- package/lib/middleware/aws-lambda/index.mjs +14 -17
- package/lib/middleware/azure-swa/index.mjs +16 -221
- package/lib/middleware/bun/index.d.ts +11 -0
- package/lib/middleware/bun/index.mjs +50 -97
- package/lib/middleware/cloudflare-pages/index.mjs +22 -31
- package/lib/middleware/deno/index.d.ts +11 -0
- package/lib/middleware/deno/index.mjs +49 -97
- package/lib/middleware/firebase/index.mjs +6 -15
- package/lib/middleware/netlify-edge/index.mjs +22 -32
- package/lib/middleware/node/index.mjs +31 -105
- package/lib/middleware/request-handler/index.d.ts +163 -88
- package/lib/middleware/request-handler/index.mjs +1458 -1260
- package/lib/middleware/vercel-edge/index.mjs +27 -36
- package/lib/modules.d.ts +11 -16
- package/lib/service-worker/index.mjs +4 -0
- package/lib/{static → ssg}/index.d.ts +45 -13
- package/lib/ssg/index.mjs +336 -0
- package/lib/vite/index.d.ts +38 -10
- package/lib/vite/index.mjs +2067 -26841
- package/modules.d.ts +11 -16
- package/package.json +62 -67
- 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/static/node.mjs +0 -1086
- 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
|
@@ -36,6 +36,17 @@ export declare interface QwikRouterDenoOptions extends ServerRenderOptions {
|
|
|
36
36
|
/** Set the Cache-Control header for all static files */
|
|
37
37
|
cacheControl?: string;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Provide a function that computes the origin of the server, used to resolve relative URLs and
|
|
41
|
+
* validate the request origin against CSRF attacks.
|
|
42
|
+
*
|
|
43
|
+
* When not specified, it defaults to the `ORIGIN` environment variable (if set).
|
|
44
|
+
*
|
|
45
|
+
* If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
|
|
46
|
+
* production use.
|
|
47
|
+
*/
|
|
48
|
+
getOrigin?: (request: Request, info?: ServeHandlerInfo) => string | null;
|
|
49
|
+
/** Provide a function that returns a `ClientConn` for the given request. */
|
|
39
50
|
getClientConn?: (request: Request, info: ServeHandlerInfo) => ClientConn;
|
|
40
51
|
}
|
|
41
52
|
|
|
@@ -1,84 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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, n as normalizeRequestUrl } from '../../chunks/url.mjs';
|
|
4
|
+
import { join, fromFileUrl, extname } from 'https://deno.land/std/path/mod.ts';
|
|
5
|
+
import { isDev } from '@qwik.dev/core/build';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
asx: "video/x-ms-asf",
|
|
14
|
-
avi: "video/x-msvideo",
|
|
15
|
-
avif: "image/avif",
|
|
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";
|
|
62
|
-
function createQwikRouter(opts) {
|
|
63
|
-
var _a;
|
|
64
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
65
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
66
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
67
|
-
} else if (!opts.qwikRouterConfig) {
|
|
68
|
-
throw new Error("qwikRouterConfig is required.");
|
|
7
|
+
function getRequestUrl(request, opts, info) {
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
const origin = opts.getOrigin?.(request, info) ?? Deno.env?.get?.("ORIGIN");
|
|
10
|
+
if (!origin) {
|
|
11
|
+
return url;
|
|
69
12
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_verifySerializable
|
|
74
|
-
};
|
|
13
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
|
+
}
|
|
15
|
+
function createQwikRouter(opts) {
|
|
75
16
|
if (opts.manifest) {
|
|
76
17
|
setServerPlatform(opts.manifest);
|
|
77
18
|
}
|
|
78
|
-
const staticFolder =
|
|
19
|
+
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
79
20
|
async function router(request, info) {
|
|
80
21
|
try {
|
|
81
|
-
const url =
|
|
22
|
+
const url = getRequestUrl(request, opts, info);
|
|
82
23
|
const serverRequestEv = {
|
|
83
24
|
mode: "server",
|
|
84
25
|
locale: void 0,
|
|
@@ -104,11 +45,11 @@ function createQwikRouter(opts) {
|
|
|
104
45
|
};
|
|
105
46
|
}
|
|
106
47
|
};
|
|
107
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
48
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
108
49
|
if (handledResponse) {
|
|
109
|
-
handledResponse.completion.then((
|
|
110
|
-
if (
|
|
111
|
-
console.error(
|
|
50
|
+
handledResponse.completion.then((completion) => {
|
|
51
|
+
if (completion) {
|
|
52
|
+
console.error(completion);
|
|
112
53
|
}
|
|
113
54
|
});
|
|
114
55
|
const response = await handledResponse.response;
|
|
@@ -119,25 +60,34 @@ function createQwikRouter(opts) {
|
|
|
119
60
|
return null;
|
|
120
61
|
} catch (e) {
|
|
121
62
|
console.error(e);
|
|
122
|
-
return new Response(String(e || "Error"), {
|
|
63
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
123
64
|
status: 500,
|
|
124
|
-
headers: {
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
67
|
+
"X-Error": "deno-server"
|
|
68
|
+
}
|
|
125
69
|
});
|
|
126
70
|
}
|
|
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
|
-
headers: {
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
80
|
+
"X-Not-Found": url.pathname
|
|
81
|
+
}
|
|
135
82
|
});
|
|
136
83
|
} catch (e) {
|
|
137
84
|
console.error(e);
|
|
138
|
-
return new Response(String(e || "Error"), {
|
|
85
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
139
86
|
status: 500,
|
|
140
|
-
headers: {
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
89
|
+
"X-Error": "deno-server"
|
|
90
|
+
}
|
|
141
91
|
});
|
|
142
92
|
}
|
|
143
93
|
};
|
|
@@ -147,7 +97,7 @@ function createQwikRouter(opts) {
|
|
|
147
97
|
let filePath;
|
|
148
98
|
if (fileName.includes(".")) {
|
|
149
99
|
filePath = join(staticFolder, pathname);
|
|
150
|
-
} else if (
|
|
100
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
151
101
|
filePath = join(staticFolder, pathname + "index.html");
|
|
152
102
|
} else {
|
|
153
103
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -155,13 +105,14 @@ function createQwikRouter(opts) {
|
|
|
155
105
|
return {
|
|
156
106
|
filePath,
|
|
157
107
|
// @ts-ignore
|
|
158
|
-
content: await Deno.open(filePath, {
|
|
108
|
+
content: await Deno.open(filePath, {
|
|
109
|
+
read: true
|
|
110
|
+
})
|
|
159
111
|
};
|
|
160
112
|
};
|
|
161
113
|
const staticFile = async (request) => {
|
|
162
|
-
var _a2;
|
|
163
114
|
try {
|
|
164
|
-
const url =
|
|
115
|
+
const url = getRequestUrl(request, opts);
|
|
165
116
|
if (isStaticPath(request.method || "GET", url)) {
|
|
166
117
|
const { filePath, content } = await openStaticFile(url);
|
|
167
118
|
const ext = extname(filePath).replace(/^\./, "");
|
|
@@ -169,16 +120,19 @@ function createQwikRouter(opts) {
|
|
|
169
120
|
status: 200,
|
|
170
121
|
headers: {
|
|
171
122
|
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
172
|
-
"Cache-Control":
|
|
123
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
173
124
|
}
|
|
174
125
|
});
|
|
175
126
|
}
|
|
176
127
|
return null;
|
|
177
128
|
} catch (e) {
|
|
178
129
|
console.error(e);
|
|
179
|
-
return new Response(String(e || "Error"), {
|
|
130
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
180
131
|
status: 500,
|
|
181
|
-
headers: {
|
|
132
|
+
headers: {
|
|
133
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
134
|
+
"X-Error": "deno-server"
|
|
135
|
+
}
|
|
182
136
|
});
|
|
183
137
|
}
|
|
184
138
|
};
|
|
@@ -188,8 +142,6 @@ function createQwikRouter(opts) {
|
|
|
188
142
|
staticFile
|
|
189
143
|
};
|
|
190
144
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
createQwikRouter
|
|
195
|
-
};
|
|
145
|
+
const createQwikCity = createQwikRouter;
|
|
146
|
+
|
|
147
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
|
|
2
|
+
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
|
-
|
|
5
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
6
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
-
} else if (!opts.qwikRouterConfig) {
|
|
8
|
-
throw new Error("qwikRouterConfig is required.");
|
|
9
|
-
}
|
|
10
|
-
const { staticFile, notFound, router } = createQwikRouterNode({
|
|
4
|
+
const { staticFile, notFound, router } = createQwikRouter$1({
|
|
11
5
|
render: opts.render,
|
|
12
6
|
manifest: opts.manifest,
|
|
13
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
14
7
|
static: {
|
|
15
8
|
cacheControl: "public, max-age=31557600"
|
|
16
9
|
},
|
|
@@ -29,8 +22,6 @@ function createQwikRouter(opts) {
|
|
|
29
22
|
};
|
|
30
23
|
return qwikApp;
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
createQwikRouter
|
|
36
|
-
};
|
|
25
|
+
const createQwikCity = createQwikRouter;
|
|
26
|
+
|
|
27
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
+
import { isDev } from '@qwik.dev/core/build';
|
|
4
|
+
|
|
7
5
|
function createQwikRouter(opts) {
|
|
8
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
9
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
10
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
11
|
-
} else if (!opts.qwikRouterConfig) {
|
|
12
|
-
throw new Error("qwikRouterConfig is required.");
|
|
13
|
-
}
|
|
14
|
-
const qwikSerializer = {
|
|
15
|
-
_deserialize,
|
|
16
|
-
_serialize,
|
|
17
|
-
_verifySerializable
|
|
18
|
-
};
|
|
19
6
|
if (opts.manifest) {
|
|
20
7
|
setServerPlatform(opts.manifest);
|
|
21
8
|
}
|
|
@@ -41,19 +28,18 @@ function createQwikRouter(opts) {
|
|
|
41
28
|
return writable;
|
|
42
29
|
},
|
|
43
30
|
getClientConn: () => {
|
|
44
|
-
var _a;
|
|
45
31
|
return {
|
|
46
32
|
ip: context.ip,
|
|
47
|
-
country:
|
|
33
|
+
country: context.geo.country?.code
|
|
48
34
|
};
|
|
49
35
|
},
|
|
50
36
|
platform: context
|
|
51
37
|
};
|
|
52
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
38
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
53
39
|
if (handledResponse) {
|
|
54
|
-
handledResponse.completion.then((
|
|
55
|
-
if (
|
|
56
|
-
console.error(
|
|
40
|
+
handledResponse.completion.then((completion) => {
|
|
41
|
+
if (completion) {
|
|
42
|
+
console.error(completion);
|
|
57
43
|
}
|
|
58
44
|
});
|
|
59
45
|
const response = await handledResponse.response;
|
|
@@ -61,23 +47,27 @@ function createQwikRouter(opts) {
|
|
|
61
47
|
return response;
|
|
62
48
|
}
|
|
63
49
|
}
|
|
64
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
50
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
65
51
|
return new Response(notFoundHtml, {
|
|
66
52
|
status: 404,
|
|
67
|
-
headers: {
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
55
|
+
"X-Not-Found": url.pathname
|
|
56
|
+
}
|
|
68
57
|
});
|
|
69
58
|
} catch (e) {
|
|
70
59
|
console.error(e);
|
|
71
|
-
return new Response(String(e || "Error"), {
|
|
60
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
72
61
|
status: 500,
|
|
73
|
-
headers: {
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
64
|
+
"X-Error": "netlify-edge"
|
|
65
|
+
}
|
|
74
66
|
});
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
return onNetlifyEdgeRequest;
|
|
78
70
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
createQwikRouter
|
|
83
|
-
};
|
|
71
|
+
const createQwikCity = createQwikRouter;
|
|
72
|
+
|
|
73
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,71 +1,12 @@
|
|
|
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 { n as normalizeRequestUrl, M as MIME_TYPES } from '../../chunks/url.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
|
-
function computeOrigin(req, opts) {
|
|
66
|
-
var _a;
|
|
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);
|
|
68
|
-
}
|
|
69
10
|
function fallbackOrigin(req) {
|
|
70
11
|
const { PROTOCOL_HEADER, HOST_HEADER } = process.env;
|
|
71
12
|
const headers = req.headers;
|
|
@@ -74,17 +15,22 @@ function fallbackOrigin(req) {
|
|
|
74
15
|
const host = headers[hostHeader];
|
|
75
16
|
return `${protocol}://${host}`;
|
|
76
17
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
18
|
+
function computeOrigin(req, opts) {
|
|
19
|
+
return opts?.getOrigin?.(req) ?? opts?.origin ?? process.env.ORIGIN ?? fallbackOrigin(req);
|
|
79
20
|
}
|
|
80
21
|
function isIgnoredError(message = "") {
|
|
81
|
-
const ignoredErrors = [
|
|
22
|
+
const ignoredErrors = [
|
|
23
|
+
"The stream has been destroyed",
|
|
24
|
+
"write after end"
|
|
25
|
+
];
|
|
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
|
-
|
|
87
|
-
|
|
30
|
+
return normalizeRequestUrl(url, base);
|
|
31
|
+
}
|
|
32
|
+
function getUrl(req, origin) {
|
|
33
|
+
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
88
34
|
}
|
|
89
35
|
async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
90
36
|
const requestHeaders = new Headers();
|
|
@@ -172,42 +118,25 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
|
172
118
|
ssr: true,
|
|
173
119
|
incomingMessage: req,
|
|
174
120
|
node: process.versions.node
|
|
175
|
-
// Weirdly needed to make typecheck of insights happy
|
|
176
121
|
},
|
|
177
122
|
locale: void 0
|
|
178
123
|
};
|
|
179
124
|
return serverRequestEv;
|
|
180
125
|
}
|
|
181
126
|
|
|
182
|
-
// packages/qwik-router/src/middleware/node/index.ts
|
|
183
127
|
function createQwikRouter(opts) {
|
|
184
|
-
var _a;
|
|
185
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
186
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
187
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
188
|
-
} else if (!opts.qwikRouterConfig) {
|
|
189
|
-
throw new Error("qwikRouterConfig is required.");
|
|
190
|
-
}
|
|
191
|
-
const qwikSerializer = {
|
|
192
|
-
_deserialize,
|
|
193
|
-
_serialize,
|
|
194
|
-
_verifySerializable
|
|
195
|
-
};
|
|
196
128
|
if (opts.manifest) {
|
|
197
129
|
setServerPlatform(opts.manifest);
|
|
198
130
|
}
|
|
199
|
-
const staticFolder =
|
|
131
|
+
const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
200
132
|
const router = async (req, res, next) => {
|
|
201
133
|
try {
|
|
202
134
|
const origin = computeOrigin(req, opts);
|
|
203
|
-
const serverRequestEv = await fromNodeHttp(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
opts.getClientConn
|
|
209
|
-
);
|
|
210
|
-
const handled = await requestHandler(serverRequestEv, opts, qwikSerializer);
|
|
135
|
+
const serverRequestEv = await fromNodeHttp(getUrl(req, origin), req, res, "server", opts.getClientConn);
|
|
136
|
+
if (isDev && opts.platform) {
|
|
137
|
+
Object.assign(serverRequestEv.platform, opts.platform);
|
|
138
|
+
}
|
|
139
|
+
const handled = await requestHandler(serverRequestEv, opts);
|
|
211
140
|
if (handled) {
|
|
212
141
|
const err = await handled.completion;
|
|
213
142
|
if (err) {
|
|
@@ -228,7 +157,7 @@ function createQwikRouter(opts) {
|
|
|
228
157
|
if (!res.headersSent) {
|
|
229
158
|
const origin = computeOrigin(req, opts);
|
|
230
159
|
const url = getUrl(req, origin);
|
|
231
|
-
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
160
|
+
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
232
161
|
res.writeHead(404, {
|
|
233
162
|
"Content-Type": "text/html; charset=utf-8",
|
|
234
163
|
"X-Not-Found": url.pathname
|
|
@@ -241,7 +170,6 @@ function createQwikRouter(opts) {
|
|
|
241
170
|
}
|
|
242
171
|
};
|
|
243
172
|
const staticFile = async (req, res, next) => {
|
|
244
|
-
var _a2;
|
|
245
173
|
try {
|
|
246
174
|
const origin = computeOrigin(req, opts);
|
|
247
175
|
const url = getUrl(req, origin);
|
|
@@ -250,7 +178,7 @@ function createQwikRouter(opts) {
|
|
|
250
178
|
let filePath;
|
|
251
179
|
if (basename(pathname).includes(".")) {
|
|
252
180
|
filePath = join(staticFolder, pathname);
|
|
253
|
-
} else if (
|
|
181
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
254
182
|
filePath = join(staticFolder, pathname + "index.html");
|
|
255
183
|
} else {
|
|
256
184
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -262,7 +190,7 @@ function createQwikRouter(opts) {
|
|
|
262
190
|
if (contentType) {
|
|
263
191
|
res.setHeader("Content-Type", contentType);
|
|
264
192
|
}
|
|
265
|
-
if (
|
|
193
|
+
if (opts.static?.cacheControl) {
|
|
266
194
|
res.setHeader("Cache-Control", opts.static.cacheControl);
|
|
267
195
|
}
|
|
268
196
|
stream.pipe(res);
|
|
@@ -280,8 +208,6 @@ function createQwikRouter(opts) {
|
|
|
280
208
|
staticFile
|
|
281
209
|
};
|
|
282
210
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
createQwikRouter
|
|
287
|
-
};
|
|
211
|
+
const createQwikCity = createQwikRouter;
|
|
212
|
+
|
|
213
|
+
export { createQwikCity, createQwikRouter };
|