@qwik.dev/router 2.0.0-beta.3 → 2.0.0-beta.30
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/mime-types.mjs +52 -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 +820 -0
- package/lib/chunks/system.mjs +333 -0
- package/lib/chunks/use-functions.qwik.mjs +35 -0
- package/lib/chunks/worker-thread.qwik.mjs +2572 -0
- package/lib/index.d.ts +358 -141
- package/lib/index.qwik.mjs +865 -1156
- package/lib/middleware/aws-lambda/index.d.ts +3 -2
- package/lib/middleware/aws-lambda/index.mjs +15 -13
- package/lib/middleware/azure-swa/index.mjs +17 -218
- package/lib/middleware/bun/index.d.ts +11 -0
- package/lib/middleware/bun/index.mjs +51 -94
- package/lib/middleware/cloudflare-pages/index.mjs +23 -28
- package/lib/middleware/deno/index.d.ts +11 -0
- package/lib/middleware/deno/index.mjs +50 -94
- package/lib/middleware/firebase/index.mjs +7 -11
- package/lib/middleware/netlify-edge/index.mjs +23 -29
- package/lib/middleware/node/index.mjs +31 -100
- package/lib/middleware/request-handler/index.d.ts +161 -83
- package/lib/middleware/request-handler/index.mjs +1458 -1257
- package/lib/middleware/vercel-edge/index.mjs +28 -33
- 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,29 @@
|
|
|
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 } from '../../chunks/mime-types.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
|
-
|
|
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";
|
|
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;
|
|
12
|
+
}
|
|
13
|
+
return new URL(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
|
+
}
|
|
62
15
|
function createQwikRouter(opts) {
|
|
63
|
-
var _a;
|
|
64
16
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
65
|
-
console.warn("qwikCityPlan is deprecated.
|
|
17
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
66
18
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
67
|
-
} else if (!opts.qwikRouterConfig) {
|
|
68
|
-
throw new Error("qwikRouterConfig is required.");
|
|
69
19
|
}
|
|
70
|
-
const qwikSerializer = {
|
|
71
|
-
_deserialize,
|
|
72
|
-
_serialize,
|
|
73
|
-
_verifySerializable
|
|
74
|
-
};
|
|
75
20
|
if (opts.manifest) {
|
|
76
21
|
setServerPlatform(opts.manifest);
|
|
77
22
|
}
|
|
78
|
-
const staticFolder =
|
|
23
|
+
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
79
24
|
async function router(request, info) {
|
|
80
25
|
try {
|
|
81
|
-
const url =
|
|
26
|
+
const url = getRequestUrl(request, opts, info);
|
|
82
27
|
const serverRequestEv = {
|
|
83
28
|
mode: "server",
|
|
84
29
|
locale: void 0,
|
|
@@ -104,11 +49,11 @@ function createQwikRouter(opts) {
|
|
|
104
49
|
};
|
|
105
50
|
}
|
|
106
51
|
};
|
|
107
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
52
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
108
53
|
if (handledResponse) {
|
|
109
|
-
handledResponse.completion.then((
|
|
110
|
-
if (
|
|
111
|
-
console.error(
|
|
54
|
+
handledResponse.completion.then((completion) => {
|
|
55
|
+
if (completion) {
|
|
56
|
+
console.error(completion);
|
|
112
57
|
}
|
|
113
58
|
});
|
|
114
59
|
const response = await handledResponse.response;
|
|
@@ -119,25 +64,34 @@ function createQwikRouter(opts) {
|
|
|
119
64
|
return null;
|
|
120
65
|
} catch (e) {
|
|
121
66
|
console.error(e);
|
|
122
|
-
return new Response(String(e || "Error"), {
|
|
67
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
123
68
|
status: 500,
|
|
124
|
-
headers: {
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
71
|
+
"X-Error": "deno-server"
|
|
72
|
+
}
|
|
125
73
|
});
|
|
126
74
|
}
|
|
127
75
|
}
|
|
128
76
|
const notFound = async (request) => {
|
|
129
77
|
try {
|
|
130
|
-
const url =
|
|
131
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
78
|
+
const url = getRequestUrl(request, opts);
|
|
79
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
132
80
|
return new Response(notFoundHtml, {
|
|
133
81
|
status: 404,
|
|
134
|
-
headers: {
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
84
|
+
"X-Not-Found": url.pathname
|
|
85
|
+
}
|
|
135
86
|
});
|
|
136
87
|
} catch (e) {
|
|
137
88
|
console.error(e);
|
|
138
|
-
return new Response(String(e || "Error"), {
|
|
89
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
139
90
|
status: 500,
|
|
140
|
-
headers: {
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
93
|
+
"X-Error": "deno-server"
|
|
94
|
+
}
|
|
141
95
|
});
|
|
142
96
|
}
|
|
143
97
|
};
|
|
@@ -147,7 +101,7 @@ function createQwikRouter(opts) {
|
|
|
147
101
|
let filePath;
|
|
148
102
|
if (fileName.includes(".")) {
|
|
149
103
|
filePath = join(staticFolder, pathname);
|
|
150
|
-
} else if (
|
|
104
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
151
105
|
filePath = join(staticFolder, pathname + "index.html");
|
|
152
106
|
} else {
|
|
153
107
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -155,13 +109,14 @@ function createQwikRouter(opts) {
|
|
|
155
109
|
return {
|
|
156
110
|
filePath,
|
|
157
111
|
// @ts-ignore
|
|
158
|
-
content: await Deno.open(filePath, {
|
|
112
|
+
content: await Deno.open(filePath, {
|
|
113
|
+
read: true
|
|
114
|
+
})
|
|
159
115
|
};
|
|
160
116
|
};
|
|
161
117
|
const staticFile = async (request) => {
|
|
162
|
-
var _a2;
|
|
163
118
|
try {
|
|
164
|
-
const url =
|
|
119
|
+
const url = getRequestUrl(request, opts);
|
|
165
120
|
if (isStaticPath(request.method || "GET", url)) {
|
|
166
121
|
const { filePath, content } = await openStaticFile(url);
|
|
167
122
|
const ext = extname(filePath).replace(/^\./, "");
|
|
@@ -169,16 +124,19 @@ function createQwikRouter(opts) {
|
|
|
169
124
|
status: 200,
|
|
170
125
|
headers: {
|
|
171
126
|
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
172
|
-
"Cache-Control":
|
|
127
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
173
128
|
}
|
|
174
129
|
});
|
|
175
130
|
}
|
|
176
131
|
return null;
|
|
177
132
|
} catch (e) {
|
|
178
133
|
console.error(e);
|
|
179
|
-
return new Response(String(e || "Error"), {
|
|
134
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
180
135
|
status: 500,
|
|
181
|
-
headers: {
|
|
136
|
+
headers: {
|
|
137
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
138
|
+
"X-Error": "deno-server"
|
|
139
|
+
}
|
|
182
140
|
});
|
|
183
141
|
}
|
|
184
142
|
};
|
|
@@ -188,8 +146,6 @@ function createQwikRouter(opts) {
|
|
|
188
146
|
staticFile
|
|
189
147
|
};
|
|
190
148
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
createQwikRouter
|
|
195
|
-
};
|
|
149
|
+
const createQwikCity = createQwikRouter;
|
|
150
|
+
|
|
151
|
+
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,12 @@
|
|
|
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
6
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
9
|
-
console.warn("qwikCityPlan is deprecated.
|
|
7
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
10
8
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
11
|
-
} else if (!opts.qwikRouterConfig) {
|
|
12
|
-
throw new Error("qwikRouterConfig is required.");
|
|
13
9
|
}
|
|
14
|
-
const qwikSerializer = {
|
|
15
|
-
_deserialize,
|
|
16
|
-
_serialize,
|
|
17
|
-
_verifySerializable
|
|
18
|
-
};
|
|
19
10
|
if (opts.manifest) {
|
|
20
11
|
setServerPlatform(opts.manifest);
|
|
21
12
|
}
|
|
@@ -41,19 +32,18 @@ function createQwikRouter(opts) {
|
|
|
41
32
|
return writable;
|
|
42
33
|
},
|
|
43
34
|
getClientConn: () => {
|
|
44
|
-
var _a;
|
|
45
35
|
return {
|
|
46
36
|
ip: context.ip,
|
|
47
|
-
country:
|
|
37
|
+
country: context.geo.country?.code
|
|
48
38
|
};
|
|
49
39
|
},
|
|
50
40
|
platform: context
|
|
51
41
|
};
|
|
52
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
42
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
53
43
|
if (handledResponse) {
|
|
54
|
-
handledResponse.completion.then((
|
|
55
|
-
if (
|
|
56
|
-
console.error(
|
|
44
|
+
handledResponse.completion.then((completion) => {
|
|
45
|
+
if (completion) {
|
|
46
|
+
console.error(completion);
|
|
57
47
|
}
|
|
58
48
|
});
|
|
59
49
|
const response = await handledResponse.response;
|
|
@@ -61,23 +51,27 @@ function createQwikRouter(opts) {
|
|
|
61
51
|
return response;
|
|
62
52
|
}
|
|
63
53
|
}
|
|
64
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
54
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
65
55
|
return new Response(notFoundHtml, {
|
|
66
56
|
status: 404,
|
|
67
|
-
headers: {
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
59
|
+
"X-Not-Found": url.pathname
|
|
60
|
+
}
|
|
68
61
|
});
|
|
69
62
|
} catch (e) {
|
|
70
63
|
console.error(e);
|
|
71
|
-
return new Response(String(e || "Error"), {
|
|
64
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
72
65
|
status: 500,
|
|
73
|
-
headers: {
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
68
|
+
"X-Error": "netlify-edge"
|
|
69
|
+
}
|
|
74
70
|
});
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
return onNetlifyEdgeRequest;
|
|
78
74
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
createQwikRouter
|
|
83
|
-
};
|
|
75
|
+
const createQwikCity = createQwikRouter;
|
|
76
|
+
|
|
77
|
+
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 { 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
|
-
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,18 +15,24 @@ 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
30
|
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
|
|
87
31
|
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
|
|
88
32
|
}
|
|
33
|
+
function getUrl(req, origin) {
|
|
34
|
+
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
35
|
+
}
|
|
89
36
|
async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
90
37
|
const requestHeaders = new Headers();
|
|
91
38
|
const nodeRequestHeaders = req.headers;
|
|
@@ -172,42 +119,29 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
|
172
119
|
ssr: true,
|
|
173
120
|
incomingMessage: req,
|
|
174
121
|
node: process.versions.node
|
|
175
|
-
// Weirdly needed to make typecheck of insights happy
|
|
176
122
|
},
|
|
177
123
|
locale: void 0
|
|
178
124
|
};
|
|
179
125
|
return serverRequestEv;
|
|
180
126
|
}
|
|
181
127
|
|
|
182
|
-
// packages/qwik-router/src/middleware/node/index.ts
|
|
183
128
|
function createQwikRouter(opts) {
|
|
184
|
-
var _a;
|
|
185
129
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
186
|
-
console.warn("qwikCityPlan is deprecated.
|
|
130
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
187
131
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
188
|
-
} else if (!opts.qwikRouterConfig) {
|
|
189
|
-
throw new Error("qwikRouterConfig is required.");
|
|
190
132
|
}
|
|
191
|
-
const qwikSerializer = {
|
|
192
|
-
_deserialize,
|
|
193
|
-
_serialize,
|
|
194
|
-
_verifySerializable
|
|
195
|
-
};
|
|
196
133
|
if (opts.manifest) {
|
|
197
134
|
setServerPlatform(opts.manifest);
|
|
198
135
|
}
|
|
199
|
-
const staticFolder =
|
|
136
|
+
const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
200
137
|
const router = async (req, res, next) => {
|
|
201
138
|
try {
|
|
202
139
|
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);
|
|
140
|
+
const serverRequestEv = await fromNodeHttp(getUrl(req, origin), req, res, "server", opts.getClientConn);
|
|
141
|
+
if (isDev && opts.platform) {
|
|
142
|
+
Object.assign(serverRequestEv.platform, opts.platform);
|
|
143
|
+
}
|
|
144
|
+
const handled = await requestHandler(serverRequestEv, opts);
|
|
211
145
|
if (handled) {
|
|
212
146
|
const err = await handled.completion;
|
|
213
147
|
if (err) {
|
|
@@ -228,7 +162,7 @@ function createQwikRouter(opts) {
|
|
|
228
162
|
if (!res.headersSent) {
|
|
229
163
|
const origin = computeOrigin(req, opts);
|
|
230
164
|
const url = getUrl(req, origin);
|
|
231
|
-
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
165
|
+
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
232
166
|
res.writeHead(404, {
|
|
233
167
|
"Content-Type": "text/html; charset=utf-8",
|
|
234
168
|
"X-Not-Found": url.pathname
|
|
@@ -241,7 +175,6 @@ function createQwikRouter(opts) {
|
|
|
241
175
|
}
|
|
242
176
|
};
|
|
243
177
|
const staticFile = async (req, res, next) => {
|
|
244
|
-
var _a2;
|
|
245
178
|
try {
|
|
246
179
|
const origin = computeOrigin(req, opts);
|
|
247
180
|
const url = getUrl(req, origin);
|
|
@@ -250,7 +183,7 @@ function createQwikRouter(opts) {
|
|
|
250
183
|
let filePath;
|
|
251
184
|
if (basename(pathname).includes(".")) {
|
|
252
185
|
filePath = join(staticFolder, pathname);
|
|
253
|
-
} else if (
|
|
186
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
254
187
|
filePath = join(staticFolder, pathname + "index.html");
|
|
255
188
|
} else {
|
|
256
189
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -262,7 +195,7 @@ function createQwikRouter(opts) {
|
|
|
262
195
|
if (contentType) {
|
|
263
196
|
res.setHeader("Content-Type", contentType);
|
|
264
197
|
}
|
|
265
|
-
if (
|
|
198
|
+
if (opts.static?.cacheControl) {
|
|
266
199
|
res.setHeader("Cache-Control", opts.static.cacheControl);
|
|
267
200
|
}
|
|
268
201
|
stream.pipe(res);
|
|
@@ -280,8 +213,6 @@ function createQwikRouter(opts) {
|
|
|
280
213
|
staticFile
|
|
281
214
|
};
|
|
282
215
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
createQwikRouter
|
|
287
|
-
};
|
|
216
|
+
const createQwikCity = createQwikRouter;
|
|
217
|
+
|
|
218
|
+
export { createQwikCity, createQwikRouter };
|