@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -57
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -76
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -34
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.d.ts +9 -16
- package/lib/adapters/shared/vite/index.mjs +280 -293
- package/lib/adapters/ssg/vite/index.d.ts +1 -1
- package/lib/adapters/ssg/vite/index.mjs +13 -299
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +75 -79
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +143 -0
- package/lib/chunks/head.qwik.mjs +1570 -0
- package/lib/chunks/http-error.qwik.mjs +28 -0
- package/lib/chunks/pathname.mjs +58 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +53 -0
- package/lib/chunks/route-trie-key.mjs +10 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +38 -0
- package/lib/chunks/static-file.mjs +70 -0
- package/lib/chunks/system.mjs +271 -0
- package/lib/chunks/user-response.mjs +1878 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1746 -2057
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +46 -50
- package/lib/middleware/azure-swa/index.mjs +85 -294
- package/lib/middleware/bun/index.d.ts +22 -5
- package/lib/middleware/bun/index.mjs +118 -201
- package/lib/middleware/cloudflare-pages/index.d.ts +2 -0
- package/lib/middleware/cloudflare-pages/index.mjs +103 -101
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +103 -191
- package/lib/middleware/firebase/index.mjs +22 -31
- package/lib/middleware/netlify-edge/index.d.ts +2 -0
- package/lib/middleware/netlify-edge/index.mjs +64 -80
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +298 -269
- package/lib/middleware/request-handler/index.d.ts +259 -58
- package/lib/middleware/request-handler/index.mjs +108 -1730
- package/lib/middleware/vercel-edge/index.d.ts +2 -0
- package/lib/middleware/vercel-edge/index.mjs +77 -100
- package/lib/modules.d.ts +7 -4
- package/lib/service-worker/index.mjs +14 -0
- package/lib/ssg/index.d.ts +50 -26
- package/lib/ssg/index.mjs +257 -43
- package/lib/vite/index.d.ts +59 -11
- package/lib/vite/index.mjs +2534 -27536
- package/modules.d.ts +7 -4
- package/package.json +53 -70
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -130
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -338
- package/lib/adapters/ssg/vite/index.cjs +0 -339
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2112
- package/lib/middleware/node/index.cjs +0 -310
- package/lib/middleware/request-handler/index.cjs +0 -1766
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/ssg/deno.mjs +0 -8
- package/lib/ssg/index.cjs +0 -67
- package/lib/ssg/node.cjs +0 -1128
- package/lib/ssg/node.mjs +0 -1090
- package/lib/vite/index.cjs +0 -27607
|
@@ -1,196 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
3
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
3
4
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
|
-
import {
|
|
5
|
-
getNotFound,
|
|
6
|
-
isStaticPath,
|
|
7
|
-
mergeHeadersCookies,
|
|
8
|
-
requestHandler
|
|
9
|
-
} from "../request-handler/index.mjs";
|
|
10
|
-
|
|
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/deno/index.ts
|
|
5
|
+
import { isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
64
6
|
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) return url;
|
|
11
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
12
|
+
}
|
|
13
|
+
/** @public */
|
|
65
14
|
function createQwikRouter(opts) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
} else {
|
|
154
|
-
filePath = join(staticFolder, pathname, "index.html");
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
filePath,
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
content: await Deno.open(filePath, { read: true })
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
const staticFile = async (request) => {
|
|
163
|
-
var _a2;
|
|
164
|
-
try {
|
|
165
|
-
const url = new URL(request.url);
|
|
166
|
-
if (isStaticPath(request.method || "GET", url)) {
|
|
167
|
-
const { filePath, content } = await openStaticFile(url);
|
|
168
|
-
const ext = extname(filePath).replace(/^\./, "");
|
|
169
|
-
return new Response(content.readable, {
|
|
170
|
-
status: 200,
|
|
171
|
-
headers: {
|
|
172
|
-
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
173
|
-
"Cache-Control": ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) || "max-age=3600"
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
} catch (e) {
|
|
179
|
-
console.error(e);
|
|
180
|
-
return new Response(String(e || "Error"), {
|
|
181
|
-
status: 500,
|
|
182
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
router,
|
|
188
|
-
notFound,
|
|
189
|
-
staticFile
|
|
190
|
-
};
|
|
15
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
16
|
+
const staticFolder = opts.static?.root ?? join(fromFileUrl(import.meta.url), "..", "..", "dist");
|
|
17
|
+
async function router(request, info) {
|
|
18
|
+
try {
|
|
19
|
+
const serverRequestEv = {
|
|
20
|
+
mode: "server",
|
|
21
|
+
locale: void 0,
|
|
22
|
+
url: getRequestUrl(request, opts, info),
|
|
23
|
+
env: Deno.env,
|
|
24
|
+
request: limitRequestBody(request, opts.requestBodyLimit),
|
|
25
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
26
|
+
const { readable, writable } = new TransformStream();
|
|
27
|
+
resolve(new Response(readable, {
|
|
28
|
+
status,
|
|
29
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
30
|
+
}));
|
|
31
|
+
return writable;
|
|
32
|
+
},
|
|
33
|
+
platform: { ssr: true },
|
|
34
|
+
getClientConn: () => {
|
|
35
|
+
return opts.getClientConn ? opts.getClientConn(request, info) : { ip: info.remoteAddr.hostname };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
39
|
+
if (handledResponse) {
|
|
40
|
+
handledResponse.completion.then((completion) => {
|
|
41
|
+
if (completion) console.error(completion);
|
|
42
|
+
});
|
|
43
|
+
const response = await handledResponse.response;
|
|
44
|
+
if (response) return response;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(e);
|
|
49
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
50
|
+
status: 500,
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
53
|
+
"X-Error": "deno-server"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
59
|
+
const notFound = async (_request) => {
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
const openStaticFile = async (staticFilePath) => {
|
|
63
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
64
|
+
return {
|
|
65
|
+
filePath,
|
|
66
|
+
content: await Deno.open(filePath, { read: true })
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const staticFile = async (request) => {
|
|
70
|
+
try {
|
|
71
|
+
const url = getRequestUrl(request, opts);
|
|
72
|
+
if (isStaticPath(request.method || "GET", url)) {
|
|
73
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
74
|
+
if (staticFilePath === void 0) return null;
|
|
75
|
+
const { filePath, content } = await openStaticFile(staticFilePath);
|
|
76
|
+
const ext = extname(filePath).replace(/^\./, "");
|
|
77
|
+
return new Response(content.readable, {
|
|
78
|
+
status: 200,
|
|
79
|
+
headers: {
|
|
80
|
+
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
81
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.error(e);
|
|
88
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
89
|
+
status: 500,
|
|
90
|
+
headers: {
|
|
91
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
92
|
+
"X-Error": "deno-server"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
router,
|
|
99
|
+
notFound,
|
|
100
|
+
staticFile
|
|
101
|
+
};
|
|
191
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
192
107
|
var createQwikCity = createQwikRouter;
|
|
193
|
-
export {
|
|
194
|
-
createQwikCity,
|
|
195
|
-
createQwikRouter
|
|
196
|
-
};
|
|
108
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createQwikRouter as createQwikRouter$1 } from "@qwik.dev/router/middleware/node";
|
|
2
|
+
/** @public */
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const qwikApp = (req, res) => {
|
|
23
|
-
return staticFile(req, res, () => {
|
|
24
|
-
router(req, res, () => notFound(req, res, () => {
|
|
25
|
-
}));
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
return qwikApp;
|
|
4
|
+
const { staticFile, router } = createQwikRouter$1({
|
|
5
|
+
render: opts.render,
|
|
6
|
+
manifest: opts.manifest,
|
|
7
|
+
static: { cacheControl: "public, max-age=31557600" },
|
|
8
|
+
getOrigin(req) {
|
|
9
|
+
if (process.env.IS_OFFLINE) return `http://${req.headers.host}`;
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const qwikApp = (req, res) => {
|
|
14
|
+
return staticFile(req, res, () => {
|
|
15
|
+
router(req, res, () => {});
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
return qwikApp;
|
|
29
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
30
24
|
var createQwikCity = createQwikRouter;
|
|
31
|
-
export {
|
|
32
|
-
createQwikCity,
|
|
33
|
-
createQwikRouter
|
|
34
|
-
};
|
|
25
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -22,6 +22,8 @@ export declare type QwikCityNetlifyOptions = QwikRouterNetlifyOptions;
|
|
|
22
22
|
|
|
23
23
|
/** @public */
|
|
24
24
|
export declare interface QwikRouterNetlifyOptions extends ServerRenderOptions {
|
|
25
|
+
/** Maximum request body size in bytes. Defaults to 10 MiB. */
|
|
26
|
+
requestBodyLimit?: number;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export { }
|
|
@@ -1,84 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { r as limitRequestBody } from "../../chunks/request-body-limit.mjs";
|
|
2
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
3
3
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
isStaticPath,
|
|
7
|
-
mergeHeadersCookies,
|
|
8
|
-
requestHandler
|
|
9
|
-
} from "../request-handler/index.mjs";
|
|
4
|
+
import { getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
5
|
+
/** @public */
|
|
10
6
|
function createQwikRouter(opts) {
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
return new Response(notFoundHtml, {
|
|
67
|
-
status: 404,
|
|
68
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
69
|
-
});
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.error(e);
|
|
72
|
-
return new Response(String(e || "Error"), {
|
|
73
|
-
status: 500,
|
|
74
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "netlify-edge" }
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return onNetlifyEdgeRequest;
|
|
7
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
8
|
+
async function onNetlifyEdgeRequest(request, context) {
|
|
9
|
+
try {
|
|
10
|
+
const url = new URL(request.url);
|
|
11
|
+
if (isStaticPath(request.method, url) || url.pathname.startsWith("/.netlify")) return context.next();
|
|
12
|
+
const serverRequestEv = {
|
|
13
|
+
mode: "server",
|
|
14
|
+
locale: void 0,
|
|
15
|
+
url,
|
|
16
|
+
env: Deno.env,
|
|
17
|
+
request: limitRequestBody(request, opts.requestBodyLimit),
|
|
18
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
19
|
+
const { readable, writable } = new TransformStream();
|
|
20
|
+
resolve(new Response(readable, {
|
|
21
|
+
status,
|
|
22
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
23
|
+
}));
|
|
24
|
+
return writable;
|
|
25
|
+
},
|
|
26
|
+
getClientConn: () => {
|
|
27
|
+
return {
|
|
28
|
+
ip: context.ip,
|
|
29
|
+
country: context.geo.country?.code
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
platform: context
|
|
33
|
+
};
|
|
34
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
35
|
+
if (handledResponse) {
|
|
36
|
+
handledResponse.completion.then((completion) => {
|
|
37
|
+
if (completion) console.error(completion);
|
|
38
|
+
});
|
|
39
|
+
const response = await handledResponse.response;
|
|
40
|
+
if (response) return response;
|
|
41
|
+
}
|
|
42
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
|
|
43
|
+
return new Response(notFoundHtml, {
|
|
44
|
+
status: 404,
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
47
|
+
"X-Not-Found": url.pathname
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error(e);
|
|
52
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
53
|
+
status: 500,
|
|
54
|
+
headers: {
|
|
55
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
56
|
+
"X-Error": "netlify-edge"
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return onNetlifyEdgeRequest;
|
|
79
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
80
67
|
var createQwikCity = createQwikRouter;
|
|
81
|
-
export {
|
|
82
|
-
createQwikCity,
|
|
83
|
-
createQwikRouter
|
|
84
|
-
};
|
|
68
|
+
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 */
|