@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.0
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 +1883 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1742 -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 +20 -5
- package/lib/middleware/bun/index.mjs +117 -201
- package/lib/middleware/cloudflare-pages/index.mjs +101 -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.mjs +63 -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.mjs +76 -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 +2533 -27535
- 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,206 +1,122 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { n as normalizeRequestUrl, r as MIME_TYPES, t as getStaticFilePath } from "../../chunks/static-file.mjs";
|
|
2
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
3
3
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
|
-
import {
|
|
5
|
-
_TextEncoderStream_polyfill,
|
|
6
|
-
getNotFound,
|
|
7
|
-
isStaticPath,
|
|
8
|
-
mergeHeadersCookies,
|
|
9
|
-
requestHandler
|
|
10
|
-
} from "../request-handler/index.mjs";
|
|
11
4
|
import { extname, join } from "node:path";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
avif: "image/avif",
|
|
21
|
-
bmp: "image/x-ms-bmp",
|
|
22
|
-
css: "text/css",
|
|
23
|
-
flv: "video/x-flv",
|
|
24
|
-
gif: "image/gif",
|
|
25
|
-
htm: "text/html",
|
|
26
|
-
html: "text/html",
|
|
27
|
-
ico: "image/x-icon",
|
|
28
|
-
jng: "image/x-jng",
|
|
29
|
-
jpeg: "image/jpeg",
|
|
30
|
-
jpg: "image/jpeg",
|
|
31
|
-
js: "application/javascript",
|
|
32
|
-
json: "application/json",
|
|
33
|
-
kar: "audio/midi",
|
|
34
|
-
m4a: "audio/x-m4a",
|
|
35
|
-
m4v: "video/x-m4v",
|
|
36
|
-
mid: "audio/midi",
|
|
37
|
-
midi: "audio/midi",
|
|
38
|
-
mng: "video/x-mng",
|
|
39
|
-
mov: "video/quicktime",
|
|
40
|
-
mp3: "audio/mpeg",
|
|
41
|
-
mp4: "video/mp4",
|
|
42
|
-
mpeg: "video/mpeg",
|
|
43
|
-
mpg: "video/mpeg",
|
|
44
|
-
ogg: "audio/ogg",
|
|
45
|
-
pdf: "application/pdf",
|
|
46
|
-
png: "image/png",
|
|
47
|
-
rar: "application/x-rar-compressed",
|
|
48
|
-
shtml: "text/html",
|
|
49
|
-
svg: "image/svg+xml",
|
|
50
|
-
svgz: "image/svg+xml",
|
|
51
|
-
tif: "image/tiff",
|
|
52
|
-
tiff: "image/tiff",
|
|
53
|
-
ts: "video/mp2t",
|
|
54
|
-
txt: "text/plain",
|
|
55
|
-
wbmp: "image/vnd.wap.wbmp",
|
|
56
|
-
webm: "video/webm",
|
|
57
|
-
webp: "image/webp",
|
|
58
|
-
wmv: "video/x-ms-wmv",
|
|
59
|
-
woff: "font/woff",
|
|
60
|
-
woff2: "font/woff2",
|
|
61
|
-
xml: "text/xml",
|
|
62
|
-
zip: "application/zip"
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// packages/qwik-router/src/middleware/bun/index.ts
|
|
5
|
+
import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
6
|
+
function getRequestUrl(request, opts) {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
const origin = opts.getOrigin?.(request) ?? Bun.env.ORIGIN;
|
|
9
|
+
if (!origin) return url;
|
|
10
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
11
|
+
}
|
|
12
|
+
/** @public */
|
|
66
13
|
function createQwikRouter(opts) {
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const url = new URL(request.url);
|
|
170
|
-
if (isStaticPath(request.method || "GET", url)) {
|
|
171
|
-
const { filePath, content } = await openStaticFile(url);
|
|
172
|
-
if (!await content.exists()) {
|
|
173
|
-
return new Response("Not Found", {
|
|
174
|
-
status: 404,
|
|
175
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Not-Found": url.pathname }
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const ext = extname(filePath).replace(/^\./, "");
|
|
179
|
-
return new Response(await content.stream(), {
|
|
180
|
-
status: 200,
|
|
181
|
-
headers: {
|
|
182
|
-
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
183
|
-
"Cache-Control": ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) || "max-age=3600"
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return null;
|
|
188
|
-
} catch (e) {
|
|
189
|
-
console.error(e);
|
|
190
|
-
return new Response(String(e || "Error"), {
|
|
191
|
-
status: 500,
|
|
192
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
return {
|
|
197
|
-
router,
|
|
198
|
-
notFound,
|
|
199
|
-
staticFile
|
|
200
|
-
};
|
|
14
|
+
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
15
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
16
|
+
const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
17
|
+
async function router(request) {
|
|
18
|
+
try {
|
|
19
|
+
const serverRequestEv = {
|
|
20
|
+
mode: "server",
|
|
21
|
+
locale: void 0,
|
|
22
|
+
url: getRequestUrl(request, opts),
|
|
23
|
+
env: { get(key) {
|
|
24
|
+
return Bun.env[key];
|
|
25
|
+
} },
|
|
26
|
+
request,
|
|
27
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
28
|
+
const { readable, writable } = new TransformStream();
|
|
29
|
+
resolve(new Response(readable, {
|
|
30
|
+
status,
|
|
31
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
32
|
+
}));
|
|
33
|
+
return writable;
|
|
34
|
+
},
|
|
35
|
+
platform: { ssr: true },
|
|
36
|
+
getClientConn: () => {
|
|
37
|
+
return opts.getClientConn ? opts.getClientConn(request) : {};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
41
|
+
if (handledResponse) {
|
|
42
|
+
handledResponse.completion.then((completion) => {
|
|
43
|
+
if (completion) console.error(completion);
|
|
44
|
+
});
|
|
45
|
+
const response = await handledResponse.response;
|
|
46
|
+
if (response) {
|
|
47
|
+
const status = response.status;
|
|
48
|
+
const location = response.headers.get("Location");
|
|
49
|
+
if (status >= 301 && status <= 308 && location) return new Response(null, response);
|
|
50
|
+
return response;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
57
|
+
status: 500,
|
|
58
|
+
headers: {
|
|
59
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
60
|
+
"X-Error": "bun-server"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
66
|
+
const notFound = async (_request) => {
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
69
|
+
const openStaticFile = async (staticFilePath) => {
|
|
70
|
+
const filePath = join(staticFolder, staticFilePath);
|
|
71
|
+
return {
|
|
72
|
+
filePath,
|
|
73
|
+
content: Bun.file(filePath)
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const staticFile = async (request) => {
|
|
77
|
+
try {
|
|
78
|
+
const url = getRequestUrl(request, opts);
|
|
79
|
+
if (isStaticPath(request.method || "GET", url)) {
|
|
80
|
+
const staticFilePath = getStaticFilePath(url.pathname);
|
|
81
|
+
if (staticFilePath === void 0) return null;
|
|
82
|
+
const { filePath, content } = await openStaticFile(staticFilePath);
|
|
83
|
+
if (!await content.exists()) return new Response("Not Found", {
|
|
84
|
+
status: 404,
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
87
|
+
"X-Not-Found": url.pathname
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const ext = extname(filePath).replace(/^\./, "");
|
|
91
|
+
return new Response(await content.stream(), {
|
|
92
|
+
status: 200,
|
|
93
|
+
headers: {
|
|
94
|
+
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
95
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error(e);
|
|
102
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
103
|
+
status: 500,
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
106
|
+
"X-Error": "bun-server"
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
router,
|
|
113
|
+
notFound,
|
|
114
|
+
staticFile
|
|
115
|
+
};
|
|
201
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
202
121
|
var createQwikCity = createQwikRouter;
|
|
203
|
-
export {
|
|
204
|
-
createQwikCity,
|
|
205
|
-
createQwikRouter
|
|
206
|
-
};
|
|
122
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
1
|
+
import { isDev } from "@qwik.dev/core/build";
|
|
3
2
|
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
getNotFound,
|
|
7
|
-
isStaticPath,
|
|
8
|
-
mergeHeadersCookies,
|
|
9
|
-
requestHandler
|
|
10
|
-
} from "../request-handler/index.mjs";
|
|
3
|
+
import { _TextEncoderStream_polyfill, getErrorHtml, isStaticPath, mergeHeadersCookies, requestHandler } from "@qwik.dev/router/middleware/request-handler";
|
|
4
|
+
/** @public */
|
|
11
5
|
function createQwikRouter(opts) {
|
|
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
|
-
|
|
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
|
-
console.error(e);
|
|
93
|
-
return new Response(String(e || "Error"), {
|
|
94
|
-
status: 500,
|
|
95
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "cloudflare-pages" }
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return onCloudflarePagesFetch;
|
|
6
|
+
try {
|
|
7
|
+
new globalThis.TextEncoderStream();
|
|
8
|
+
} catch {
|
|
9
|
+
globalThis.TextEncoderStream = _TextEncoderStream_polyfill;
|
|
10
|
+
}
|
|
11
|
+
if (opts.manifest) setServerPlatform(opts.manifest);
|
|
12
|
+
async function onCloudflarePagesFetch(request, env, ctx) {
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
if (isStaticPath(request.method, url)) return env.ASSETS.fetch(request);
|
|
16
|
+
const useCache = url.hostname !== "127.0.0.1" && url.hostname !== "localhost" && url.port === "" && request.method === "GET" && !request.headers.has("Cookie") && !request.headers.has("Authorization");
|
|
17
|
+
const cacheKey = new Request(url.href, request);
|
|
18
|
+
const cache = useCache ? await caches.open("custom:qwikrouter") : null;
|
|
19
|
+
if (cache) {
|
|
20
|
+
const cachedResponse = await cache.match(cacheKey);
|
|
21
|
+
if (cachedResponse) return cachedResponse;
|
|
22
|
+
}
|
|
23
|
+
const handledResponse = await requestHandler({
|
|
24
|
+
mode: "server",
|
|
25
|
+
locale: void 0,
|
|
26
|
+
url,
|
|
27
|
+
request,
|
|
28
|
+
env: { get(key) {
|
|
29
|
+
return env[key];
|
|
30
|
+
} },
|
|
31
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
32
|
+
const responseInit = {
|
|
33
|
+
status,
|
|
34
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
35
|
+
};
|
|
36
|
+
if (status === 204 || status === 205 || status === 304) {
|
|
37
|
+
resolve(new Response(null, responseInit));
|
|
38
|
+
return new WritableStream();
|
|
39
|
+
}
|
|
40
|
+
const { readable, writable } = new TransformStream();
|
|
41
|
+
resolve(new Response(readable, responseInit));
|
|
42
|
+
return writable;
|
|
43
|
+
},
|
|
44
|
+
getClientConn: () => {
|
|
45
|
+
return {
|
|
46
|
+
ip: request.headers.get("CF-connecting-ip") || "",
|
|
47
|
+
country: request.headers.get("CF-IPCountry") || ""
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
platform: {
|
|
51
|
+
request,
|
|
52
|
+
env,
|
|
53
|
+
ctx
|
|
54
|
+
}
|
|
55
|
+
}, opts);
|
|
56
|
+
if (handledResponse) {
|
|
57
|
+
handledResponse.completion.then((completion) => {
|
|
58
|
+
if (completion) console.error(completion);
|
|
59
|
+
});
|
|
60
|
+
const response = await handledResponse.response;
|
|
61
|
+
if (response) {
|
|
62
|
+
if (response.ok && cache && isSharedCacheable(response)) ctx.waitUntil(cache.put(cacheKey, response.clone()));
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getErrorHtml(404, "Not Found");
|
|
67
|
+
return new Response(notFoundHtml, {
|
|
68
|
+
status: 404,
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
71
|
+
"X-Not-Found": url.pathname
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error(e);
|
|
76
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
77
|
+
status: 500,
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
80
|
+
"X-Error": "cloudflare-pages"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return onCloudflarePagesFetch;
|
|
100
86
|
}
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
87
|
+
var uncacheableDirectives = /* @__PURE__ */ new Set([
|
|
88
|
+
"private",
|
|
89
|
+
"no-store",
|
|
90
|
+
"no-cache"
|
|
91
|
+
]);
|
|
92
|
+
var isSharedCacheable = (response) => {
|
|
93
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
94
|
+
if (!cacheControl || response.headers.has("Set-Cookie")) return false;
|
|
95
|
+
return !cacheControl.split(",").some((value) => {
|
|
96
|
+
const directive = value.trim().split("=", 1)[0].toLowerCase();
|
|
97
|
+
return uncacheableDirectives.has(directive);
|
|
98
|
+
});
|
|
105
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
var createQwikCity = createQwikRouter;
|
|
105
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -8,11 +8,7 @@ import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-ha
|
|
|
8
8
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
|
-
export declare function createQwikRouter(opts: QwikRouterDenoOptions):
|
|
12
|
-
router: (request: Request, info: ServeHandlerInfo) => Promise<Response | null>;
|
|
13
|
-
notFound: (request: Request) => Promise<Response>;
|
|
14
|
-
staticFile: (request: Request) => Promise<Response | null>;
|
|
15
|
-
};
|
|
11
|
+
export declare function createQwikRouter(opts: QwikRouterDenoOptions): QwikRouterDenoMiddleware;
|
|
16
12
|
|
|
17
13
|
/** @public */
|
|
18
14
|
export declare interface NetAddr {
|
|
@@ -27,8 +23,18 @@ export declare interface NetAddr {
|
|
|
27
23
|
*/
|
|
28
24
|
export declare type QwikCityDenoOptions = QwikRouterDenoOptions;
|
|
29
25
|
|
|
26
|
+
/** @public */
|
|
27
|
+
export declare interface QwikRouterDenoMiddleware {
|
|
28
|
+
router: (request: Request, info: ServeHandlerInfo) => Promise<Response | null>;
|
|
29
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
30
|
+
notFound: (request: Request) => Promise<Response>;
|
|
31
|
+
staticFile: (request: Request) => Promise<Response | null>;
|
|
32
|
+
}
|
|
33
|
+
|
|
30
34
|
/** @public */
|
|
31
35
|
export declare interface QwikRouterDenoOptions extends ServerRenderOptions {
|
|
36
|
+
/** Maximum request body size in bytes. Defaults to 10 MiB. */
|
|
37
|
+
requestBodyLimit?: number;
|
|
32
38
|
/** Options for serving static files */
|
|
33
39
|
static?: {
|
|
34
40
|
/** The root folder for statics files. Defaults to /dist */
|
|
@@ -36,6 +42,17 @@ export declare interface QwikRouterDenoOptions extends ServerRenderOptions {
|
|
|
36
42
|
/** Set the Cache-Control header for all static files */
|
|
37
43
|
cacheControl?: string;
|
|
38
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Provide a function that computes the origin of the server, used to resolve relative URLs and
|
|
47
|
+
* validate the request origin against CSRF attacks.
|
|
48
|
+
*
|
|
49
|
+
* When not specified, it defaults to the `ORIGIN` environment variable (if set).
|
|
50
|
+
*
|
|
51
|
+
* If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
|
|
52
|
+
* production use.
|
|
53
|
+
*/
|
|
54
|
+
getOrigin?: (request: Request, info?: ServeHandlerInfo) => string | null;
|
|
55
|
+
/** Provide a function that returns a `ClientConn` for the given request. */
|
|
39
56
|
getClientConn?: (request: Request, info: ServeHandlerInfo) => ClientConn;
|
|
40
57
|
}
|
|
41
58
|
|