@qwik.dev/router 2.0.0-beta.4 → 2.0.0-beta.41
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 +44 -58
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -23
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -20
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -77
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -35
- 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 -23
- package/lib/adapters/shared/vite/index.d.ts +9 -22
- package/lib/adapters/shared/vite/index.mjs +280 -333
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/ssg/vite/index.mjs +13 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +73 -80
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +140 -0
- package/lib/chunks/head.qwik.mjs +1202 -0
- package/lib/chunks/http-error.qwik.mjs +27 -0
- package/lib/chunks/pathname.mjs +57 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +49 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +16 -0
- package/lib/chunks/system.mjs +265 -0
- package/lib/chunks/url.mjs +59 -0
- package/lib/chunks/user-response.mjs +1730 -0
- package/lib/chunks/worker-thread.mjs +264 -0
- package/lib/index.d.ts +631 -174
- package/lib/index.qwik.mjs +1656 -1964
- package/lib/middleware/aws-lambda/index.d.ts +15 -16
- package/lib/middleware/aws-lambda/index.mjs +45 -54
- package/lib/middleware/azure-swa/index.mjs +85 -295
- package/lib/middleware/bun/index.d.ts +20 -5
- package/lib/middleware/bun/index.mjs +119 -205
- package/lib/middleware/cloudflare-pages/index.mjs +88 -105
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +105 -192
- package/lib/middleware/firebase/index.mjs +22 -35
- package/lib/middleware/netlify-edge/index.mjs +63 -81
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +299 -273
- package/lib/middleware/request-handler/index.d.ts +206 -99
- package/lib/middleware/request-handler/index.mjs +105 -1648
- package/lib/middleware/vercel-edge/index.mjs +76 -101
- package/lib/modules.d.ts +11 -16
- package/lib/service-worker/index.mjs +13 -0
- package/lib/{static → ssg}/index.d.ts +46 -22
- package/lib/ssg/index.mjs +257 -0
- package/lib/vite/index.d.ts +58 -10
- package/lib/vite/index.mjs +2471 -27446
- package/modules.d.ts +11 -16
- package/package.json +62 -70
- 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 -2022
- package/lib/middleware/node/index.cjs +0 -314
- package/lib/middleware/request-handler/index.cjs +0 -1691
- 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 -1126
- package/lib/static/node.mjs +0 -1088
- package/lib/vite/index.cjs +0 -27525
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -1,195 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
1
|
+
import { n as MIME_TYPES, t as normalizeRequestUrl } from "../../chunks/url.mjs";
|
|
2
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
3
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
5
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
-
import { mergeHeadersCookies, requestHandler } from "
|
|
7
|
-
|
|
8
|
-
// packages/qwik-router/src/middleware/request-handler/mime-types.ts
|
|
9
|
-
var MIME_TYPES = {
|
|
10
|
-
"3gp": "video/3gpp",
|
|
11
|
-
"3gpp": "video/3gpp",
|
|
12
|
-
asf: "video/x-ms-asf",
|
|
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
|
|
5
|
+
import { isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
61
6
|
import { extname, fromFileUrl, join } from "https://deno.land/std/path/mod.ts";
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} else if (!opts.qwikRouterConfig) {
|
|
68
|
-
throw new Error("qwikRouterConfig is required.");
|
|
69
|
-
}
|
|
70
|
-
const qwikSerializer = {
|
|
71
|
-
_deserialize,
|
|
72
|
-
_serialize,
|
|
73
|
-
_verifySerializable
|
|
74
|
-
};
|
|
75
|
-
if (opts.manifest) {
|
|
76
|
-
setServerPlatform(opts.manifest);
|
|
77
|
-
}
|
|
78
|
-
const staticFolder = ((_a = opts.static) == null ? void 0 : _a.root) ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
79
|
-
async function router(request, info) {
|
|
80
|
-
try {
|
|
81
|
-
const url = new URL(request.url);
|
|
82
|
-
const serverRequestEv = {
|
|
83
|
-
mode: "server",
|
|
84
|
-
locale: void 0,
|
|
85
|
-
url,
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
env: Deno.env,
|
|
88
|
-
request,
|
|
89
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
90
|
-
const { readable, writable } = new TransformStream();
|
|
91
|
-
const response = new Response(readable, {
|
|
92
|
-
status,
|
|
93
|
-
headers: mergeHeadersCookies(headers, cookies)
|
|
94
|
-
});
|
|
95
|
-
resolve(response);
|
|
96
|
-
return writable;
|
|
97
|
-
},
|
|
98
|
-
platform: {
|
|
99
|
-
ssr: true
|
|
100
|
-
},
|
|
101
|
-
getClientConn: () => {
|
|
102
|
-
return opts.getClientConn ? opts.getClientConn(request, info) : {
|
|
103
|
-
ip: info.remoteAddr.hostname
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
|
|
108
|
-
if (handledResponse) {
|
|
109
|
-
handledResponse.completion.then((v) => {
|
|
110
|
-
if (v) {
|
|
111
|
-
console.error(v);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
const response = await handledResponse.response;
|
|
115
|
-
if (response) {
|
|
116
|
-
return response;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
} catch (e) {
|
|
121
|
-
console.error(e);
|
|
122
|
-
return new Response(String(e || "Error"), {
|
|
123
|
-
status: 500,
|
|
124
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const notFound = async (request) => {
|
|
129
|
-
try {
|
|
130
|
-
const url = new URL(request.url);
|
|
131
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
132
|
-
return new Response(notFoundHtml, {
|
|
133
|
-
status: 404,
|
|
134
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
135
|
-
});
|
|
136
|
-
} catch (e) {
|
|
137
|
-
console.error(e);
|
|
138
|
-
return new Response(String(e || "Error"), {
|
|
139
|
-
status: 500,
|
|
140
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const openStaticFile = async (url) => {
|
|
145
|
-
const pathname = url.pathname;
|
|
146
|
-
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
147
|
-
let filePath;
|
|
148
|
-
if (fileName.includes(".")) {
|
|
149
|
-
filePath = join(staticFolder, pathname);
|
|
150
|
-
} else if (opts.qwikRouterConfig.trailingSlash) {
|
|
151
|
-
filePath = join(staticFolder, pathname + "index.html");
|
|
152
|
-
} else {
|
|
153
|
-
filePath = join(staticFolder, pathname, "index.html");
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
filePath,
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
content: await Deno.open(filePath, { read: true })
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
const staticFile = async (request) => {
|
|
162
|
-
var _a2;
|
|
163
|
-
try {
|
|
164
|
-
const url = new URL(request.url);
|
|
165
|
-
if (isStaticPath(request.method || "GET", url)) {
|
|
166
|
-
const { filePath, content } = await openStaticFile(url);
|
|
167
|
-
const ext = extname(filePath).replace(/^\./, "");
|
|
168
|
-
return new Response(content.readable, {
|
|
169
|
-
status: 200,
|
|
170
|
-
headers: {
|
|
171
|
-
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
172
|
-
"Cache-Control": ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) || "max-age=3600"
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
return null;
|
|
177
|
-
} catch (e) {
|
|
178
|
-
console.error(e);
|
|
179
|
-
return new Response(String(e || "Error"), {
|
|
180
|
-
status: 500,
|
|
181
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return {
|
|
186
|
-
router,
|
|
187
|
-
notFound,
|
|
188
|
-
staticFile
|
|
189
|
-
};
|
|
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) return url;
|
|
11
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
190
12
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
13
|
+
/** @public */ function createQwikRouter(opts) {
|
|
14
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
15
|
+
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
16
|
+
async function router(request, info) {
|
|
17
|
+
try {
|
|
18
|
+
const serverRequestEv = {
|
|
19
|
+
mode: "server",
|
|
20
|
+
locale: void 0,
|
|
21
|
+
url: getRequestUrl(request, opts, info),
|
|
22
|
+
env: Deno.env,
|
|
23
|
+
request: limitRequestBody(request, opts.requestBodyLimit),
|
|
24
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
25
|
+
const { readable, writable } = new TransformStream();
|
|
26
|
+
resolve(new Response(readable, {
|
|
27
|
+
status,
|
|
28
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
29
|
+
}));
|
|
30
|
+
return writable;
|
|
31
|
+
},
|
|
32
|
+
platform: { ssr: true },
|
|
33
|
+
getClientConn: () => {
|
|
34
|
+
return opts.getClientConn ? opts.getClientConn(request, info) : { ip: info.remoteAddr.hostname };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
38
|
+
if (handledResponse) {
|
|
39
|
+
handledResponse.completion.then((completion) => {
|
|
40
|
+
if (completion) console.error(completion);
|
|
41
|
+
});
|
|
42
|
+
const response = await handledResponse.response;
|
|
43
|
+
if (response) return response;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
49
|
+
status: 500,
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
52
|
+
"X-Error": "deno-server"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */ const notFound = async (_request) => {
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
const openStaticFile = async (url) => {
|
|
61
|
+
const pathname = url.pathname;
|
|
62
|
+
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
63
|
+
let filePath;
|
|
64
|
+
if (fileName.includes(".")) filePath = join(staticFolder, pathname);
|
|
65
|
+
else if (!globalThis.__NO_TRAILING_SLASH__) filePath = join(staticFolder, pathname + "index.html");
|
|
66
|
+
else filePath = join(staticFolder, pathname, "index.html");
|
|
67
|
+
return {
|
|
68
|
+
filePath,
|
|
69
|
+
content: await Deno.open(filePath, { read: true })
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const staticFile = async (request) => {
|
|
73
|
+
try {
|
|
74
|
+
const url = getRequestUrl(request, opts);
|
|
75
|
+
if (isStaticPath(request.method || "GET", url)) {
|
|
76
|
+
const { filePath, content } = await openStaticFile(url);
|
|
77
|
+
const ext = extname(filePath).replace(/^\./, "");
|
|
78
|
+
return new Response(content.readable, {
|
|
79
|
+
status: 200,
|
|
80
|
+
headers: {
|
|
81
|
+
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
82
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
90
|
+
status: 500,
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
93
|
+
"X-Error": "deno-server"
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
router,
|
|
100
|
+
notFound,
|
|
101
|
+
staticFile
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
106
|
+
* @public
|
|
107
|
+
*/ var createQwikCity = createQwikRouter;
|
|
108
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (process.env.IS_OFFLINE) {
|
|
19
|
-
return `http://${req.headers.host}`;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const qwikApp = (req, res) => {
|
|
25
|
-
return staticFile(req, res, () => {
|
|
26
|
-
router(req, res, () => notFound(req, res, () => {
|
|
27
|
-
}));
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
return qwikApp;
|
|
1
|
+
import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middleware/node";
|
|
2
|
+
/** @public */ function createQwikRouter(opts) {
|
|
3
|
+
const { staticFile, router } = createQwikRouter$1({
|
|
4
|
+
render: opts.render,
|
|
5
|
+
manifest: opts.manifest,
|
|
6
|
+
static: { cacheControl: "public, max-age=31557600" },
|
|
7
|
+
getOrigin(req) {
|
|
8
|
+
if (process.env.IS_OFFLINE) return `http://${req.headers.host}`;
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const qwikApp = (req, res) => {
|
|
13
|
+
return staticFile(req, res, () => {
|
|
14
|
+
router(req, res, () => {});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
return qwikApp;
|
|
31
18
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
21
|
+
* @public
|
|
22
|
+
*/ var createQwikCity = createQwikRouter;
|
|
23
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,83 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from "@qwik-router-not-found-paths";
|
|
3
|
-
import { isStaticPath } from "@qwik-router-static-paths";
|
|
4
|
-
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
1
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
5
2
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
-
import { mergeHeadersCookies, requestHandler } from "
|
|
7
|
-
function createQwikRouter(opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
65
|
-
return new Response(notFoundHtml, {
|
|
66
|
-
status: 404,
|
|
67
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
68
|
-
});
|
|
69
|
-
} catch (e) {
|
|
70
|
-
console.error(e);
|
|
71
|
-
return new Response(String(e || "Error"), {
|
|
72
|
-
status: 500,
|
|
73
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "netlify-edge" }
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return onNetlifyEdgeRequest;
|
|
3
|
+
import { getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
4
|
+
/** @public */ function createQwikRouter(opts) {
|
|
5
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
6
|
+
async function onNetlifyEdgeRequest(request, context) {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
if (isStaticPath(request.method, url) || url.pathname.startsWith("/.netlify")) return context.next();
|
|
10
|
+
const serverRequestEv = {
|
|
11
|
+
mode: "server",
|
|
12
|
+
locale: void 0,
|
|
13
|
+
url,
|
|
14
|
+
env: Deno.env,
|
|
15
|
+
request,
|
|
16
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
17
|
+
const { readable, writable } = new TransformStream();
|
|
18
|
+
resolve(new Response(readable, {
|
|
19
|
+
status,
|
|
20
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
21
|
+
}));
|
|
22
|
+
return writable;
|
|
23
|
+
},
|
|
24
|
+
getClientConn: () => {
|
|
25
|
+
return {
|
|
26
|
+
ip: context.ip,
|
|
27
|
+
country: context.geo.country?.code
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
platform: context
|
|
31
|
+
};
|
|
32
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
33
|
+
if (handledResponse) {
|
|
34
|
+
handledResponse.completion.then((completion) => {
|
|
35
|
+
if (completion) console.error(completion);
|
|
36
|
+
});
|
|
37
|
+
const response = await handledResponse.response;
|
|
38
|
+
if (response) return response;
|
|
39
|
+
}
|
|
40
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
|
|
41
|
+
return new Response(notFoundHtml, {
|
|
42
|
+
status: 404,
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
45
|
+
"X-Not-Found": url.pathname
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error(e);
|
|
50
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
51
|
+
status: 500,
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
54
|
+
"X-Error": "netlify-edge"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return onNetlifyEdgeRequest;
|
|
78
60
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
63
|
+
* @public
|
|
64
|
+
*/ var createQwikCity = createQwikRouter;
|
|
65
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -11,11 +11,7 @@ import type { ServerResponse } from 'node:http';
|
|
|
11
11
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
12
12
|
|
|
13
13
|
/** @public */
|
|
14
|
-
export declare function createQwikRouter(opts: QwikRouterNodeRequestOptions | QwikCityNodeRequestOptions):
|
|
15
|
-
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
16
|
-
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
17
|
-
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
18
|
-
};
|
|
14
|
+
export declare function createQwikRouter(opts: QwikRouterNodeRequestOptions | QwikCityNodeRequestOptions): QwikRouterNodeMiddleware;
|
|
19
15
|
|
|
20
16
|
/** @public */
|
|
21
17
|
export declare interface NodeRequestNextFunction {
|
|
@@ -35,8 +31,24 @@ export declare interface PlatformNode {
|
|
|
35
31
|
*/
|
|
36
32
|
export declare type QwikCityNodeRequestOptions = QwikRouterNodeRequestOptions;
|
|
37
33
|
|
|
34
|
+
/** @public */
|
|
35
|
+
export declare interface QwikRouterNodeMiddleware {
|
|
36
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction, limits?: QwikRouterNodeRequestLimits) => Promise<void>;
|
|
37
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
38
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
39
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @public */
|
|
43
|
+
export declare interface QwikRouterNodeRequestLimits {
|
|
44
|
+
/** Maximum request body size in bytes imposed by the host. */
|
|
45
|
+
bodyLimit?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
38
48
|
/** @public */
|
|
39
49
|
export declare interface QwikRouterNodeRequestOptions extends ServerRenderOptions {
|
|
50
|
+
/** Maximum request body size in bytes. Defaults to 10 MiB. */
|
|
51
|
+
requestBodyLimit?: number;
|
|
40
52
|
/** Options for serving static files */
|
|
41
53
|
static?: {
|
|
42
54
|
/** The root folder for statics files. Defaults to /dist */
|