@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
|
@@ -11,8 +11,9 @@ import { ServerResponse } from 'http';
|
|
|
11
11
|
declare interface AwsOpt {
|
|
12
12
|
render: Render;
|
|
13
13
|
manifest?: QwikManifest;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/** @deprecated Not used */
|
|
15
|
+
qwikRouterConfig?: QwikRouterConfig;
|
|
16
|
+
/** @deprecated Not used */
|
|
16
17
|
qwikCityPlan?: QwikCityPlan;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -1,14 +1,12 @@
|
|
|
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
8
|
try {
|
|
11
|
-
const { router, staticFile, notFound } =
|
|
9
|
+
const { router, staticFile, notFound } = createQwikRouter$1({
|
|
12
10
|
render: opts.render,
|
|
13
11
|
qwikRouterConfig: opts.qwikRouterConfig,
|
|
14
12
|
manifest: opts.manifest,
|
|
@@ -23,7 +21,7 @@ function createQwikRouter(opts) {
|
|
|
23
21
|
}
|
|
24
22
|
});
|
|
25
23
|
const fixPath = (pathT) => {
|
|
26
|
-
if (
|
|
24
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
27
25
|
const url = new URL(pathT, "http://aws-qwik.local");
|
|
28
26
|
if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
|
|
29
27
|
return pathT;
|
|
@@ -43,13 +41,17 @@ function createQwikRouter(opts) {
|
|
|
43
41
|
});
|
|
44
42
|
});
|
|
45
43
|
};
|
|
46
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
fixPath,
|
|
46
|
+
router,
|
|
47
|
+
staticFile,
|
|
48
|
+
notFound,
|
|
49
|
+
handle
|
|
50
|
+
};
|
|
47
51
|
} catch (err) {
|
|
48
52
|
throw new Error(err.message);
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
createQwikRouter
|
|
55
|
-
};
|
|
55
|
+
const createQwikCity = createQwikRouter;
|
|
56
|
+
|
|
57
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,216 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js
|
|
28
|
-
var require_set_cookie = __commonJS({
|
|
29
|
-
"node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js"(exports, module) {
|
|
30
|
-
"use strict";
|
|
31
|
-
var defaultParseOptions = {
|
|
32
|
-
decodeValues: true,
|
|
33
|
-
map: false,
|
|
34
|
-
silent: false
|
|
35
|
-
};
|
|
36
|
-
function isNonEmptyString(str) {
|
|
37
|
-
return typeof str === "string" && !!str.trim();
|
|
38
|
-
}
|
|
39
|
-
function parseString2(setCookieValue, options) {
|
|
40
|
-
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
41
|
-
var nameValuePairStr = parts.shift();
|
|
42
|
-
var parsed = parseNameValuePair(nameValuePairStr);
|
|
43
|
-
var name = parsed.name;
|
|
44
|
-
var value = parsed.value;
|
|
45
|
-
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
46
|
-
try {
|
|
47
|
-
value = options.decodeValues ? decodeURIComponent(value) : value;
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.error(
|
|
50
|
-
"set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.",
|
|
51
|
-
e
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
var cookie = {
|
|
55
|
-
name,
|
|
56
|
-
value
|
|
57
|
-
};
|
|
58
|
-
parts.forEach(function(part) {
|
|
59
|
-
var sides = part.split("=");
|
|
60
|
-
var key = sides.shift().trimLeft().toLowerCase();
|
|
61
|
-
var value2 = sides.join("=");
|
|
62
|
-
if (key === "expires") {
|
|
63
|
-
cookie.expires = new Date(value2);
|
|
64
|
-
} else if (key === "max-age") {
|
|
65
|
-
cookie.maxAge = parseInt(value2, 10);
|
|
66
|
-
} else if (key === "secure") {
|
|
67
|
-
cookie.secure = true;
|
|
68
|
-
} else if (key === "httponly") {
|
|
69
|
-
cookie.httpOnly = true;
|
|
70
|
-
} else if (key === "samesite") {
|
|
71
|
-
cookie.sameSite = value2;
|
|
72
|
-
} else {
|
|
73
|
-
cookie[key] = value2;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return cookie;
|
|
77
|
-
}
|
|
78
|
-
function parseNameValuePair(nameValuePairStr) {
|
|
79
|
-
var name = "";
|
|
80
|
-
var value = "";
|
|
81
|
-
var nameValueArr = nameValuePairStr.split("=");
|
|
82
|
-
if (nameValueArr.length > 1) {
|
|
83
|
-
name = nameValueArr.shift();
|
|
84
|
-
value = nameValueArr.join("=");
|
|
85
|
-
} else {
|
|
86
|
-
value = nameValuePairStr;
|
|
87
|
-
}
|
|
88
|
-
return { name, value };
|
|
89
|
-
}
|
|
90
|
-
function parse(input, options) {
|
|
91
|
-
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
92
|
-
if (!input) {
|
|
93
|
-
if (!options.map) {
|
|
94
|
-
return [];
|
|
95
|
-
} else {
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (input.headers) {
|
|
100
|
-
if (typeof input.headers.getSetCookie === "function") {
|
|
101
|
-
input = input.headers.getSetCookie();
|
|
102
|
-
} else if (input.headers["set-cookie"]) {
|
|
103
|
-
input = input.headers["set-cookie"];
|
|
104
|
-
} else {
|
|
105
|
-
var sch = input.headers[Object.keys(input.headers).find(function(key) {
|
|
106
|
-
return key.toLowerCase() === "set-cookie";
|
|
107
|
-
})];
|
|
108
|
-
if (!sch && input.headers.cookie && !options.silent) {
|
|
109
|
-
console.warn(
|
|
110
|
-
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
input = sch;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (!Array.isArray(input)) {
|
|
117
|
-
input = [input];
|
|
118
|
-
}
|
|
119
|
-
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
120
|
-
if (!options.map) {
|
|
121
|
-
return input.filter(isNonEmptyString).map(function(str) {
|
|
122
|
-
return parseString2(str, options);
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
var cookies = {};
|
|
126
|
-
return input.filter(isNonEmptyString).reduce(function(cookies2, str) {
|
|
127
|
-
var cookie = parseString2(str, options);
|
|
128
|
-
cookies2[cookie.name] = cookie;
|
|
129
|
-
return cookies2;
|
|
130
|
-
}, cookies);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function splitCookiesString(cookiesString) {
|
|
134
|
-
if (Array.isArray(cookiesString)) {
|
|
135
|
-
return cookiesString;
|
|
136
|
-
}
|
|
137
|
-
if (typeof cookiesString !== "string") {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
var cookiesStrings = [];
|
|
141
|
-
var pos = 0;
|
|
142
|
-
var start;
|
|
143
|
-
var ch;
|
|
144
|
-
var lastComma;
|
|
145
|
-
var nextStart;
|
|
146
|
-
var cookiesSeparatorFound;
|
|
147
|
-
function skipWhitespace() {
|
|
148
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
149
|
-
pos += 1;
|
|
150
|
-
}
|
|
151
|
-
return pos < cookiesString.length;
|
|
152
|
-
}
|
|
153
|
-
function notSpecialChar() {
|
|
154
|
-
ch = cookiesString.charAt(pos);
|
|
155
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
156
|
-
}
|
|
157
|
-
while (pos < cookiesString.length) {
|
|
158
|
-
start = pos;
|
|
159
|
-
cookiesSeparatorFound = false;
|
|
160
|
-
while (skipWhitespace()) {
|
|
161
|
-
ch = cookiesString.charAt(pos);
|
|
162
|
-
if (ch === ",") {
|
|
163
|
-
lastComma = pos;
|
|
164
|
-
pos += 1;
|
|
165
|
-
skipWhitespace();
|
|
166
|
-
nextStart = pos;
|
|
167
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
|
168
|
-
pos += 1;
|
|
169
|
-
}
|
|
170
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
171
|
-
cookiesSeparatorFound = true;
|
|
172
|
-
pos = nextStart;
|
|
173
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
174
|
-
start = pos;
|
|
175
|
-
} else {
|
|
176
|
-
pos = lastComma + 1;
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
pos += 1;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
183
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return cookiesStrings;
|
|
187
|
-
}
|
|
188
|
-
module.exports = parse;
|
|
189
|
-
module.exports.parse = parse;
|
|
190
|
-
module.exports.parseString = parseString2;
|
|
191
|
-
module.exports.splitCookiesString = splitCookiesString;
|
|
192
|
-
}
|
|
193
|
-
});
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { requestHandler, isStaticPath, getNotFound } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
import { parseString } from 'set-cookie-parser';
|
|
194
4
|
|
|
195
|
-
// packages/qwik-router/src/middleware/azure-swa/index.ts
|
|
196
|
-
var import_set_cookie_parser = __toESM(require_set_cookie(), 1);
|
|
197
|
-
import { getNotFound } from "@qwik-router-not-found-paths";
|
|
198
|
-
import { isStaticPath } from "@qwik-router-static-paths";
|
|
199
|
-
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
200
|
-
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
201
|
-
import { requestHandler } from "../request-handler/index.mjs";
|
|
202
5
|
function createQwikRouter(opts) {
|
|
203
6
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
204
|
-
console.warn("qwikCityPlan is deprecated.
|
|
7
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
205
8
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
206
|
-
} else if (!opts.qwikRouterConfig) {
|
|
207
|
-
throw new Error("qwikRouterConfig is required.");
|
|
208
9
|
}
|
|
209
|
-
const qwikSerializer = {
|
|
210
|
-
_deserialize,
|
|
211
|
-
_serialize,
|
|
212
|
-
_verifySerializable
|
|
213
|
-
};
|
|
214
10
|
if (opts.manifest) {
|
|
215
11
|
setServerPlatform(opts.manifest);
|
|
216
12
|
}
|
|
@@ -238,7 +34,7 @@ function createQwikRouter(opts) {
|
|
|
238
34
|
status,
|
|
239
35
|
body: new Uint8Array(),
|
|
240
36
|
headers: {},
|
|
241
|
-
cookies: cookies.headers().map((header) =>
|
|
37
|
+
cookies: cookies.headers().map((header) => parseString(header))
|
|
242
38
|
};
|
|
243
39
|
headers.forEach((value, key) => response.headers[key] = value);
|
|
244
40
|
return new WritableStream({
|
|
@@ -262,7 +58,7 @@ function createQwikRouter(opts) {
|
|
|
262
58
|
};
|
|
263
59
|
}
|
|
264
60
|
};
|
|
265
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
61
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
266
62
|
if (handledResponse) {
|
|
267
63
|
handledResponse.completion.then((err) => {
|
|
268
64
|
if (err) {
|
|
@@ -274,24 +70,27 @@ function createQwikRouter(opts) {
|
|
|
274
70
|
return response;
|
|
275
71
|
}
|
|
276
72
|
}
|
|
277
|
-
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
73
|
+
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
278
74
|
return {
|
|
279
75
|
status: 404,
|
|
280
|
-
headers: {
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
78
|
+
"X-Not-Found": url.pathname
|
|
79
|
+
},
|
|
281
80
|
body: notFoundHtml
|
|
282
81
|
};
|
|
283
82
|
} catch (e) {
|
|
284
83
|
console.error(e);
|
|
285
84
|
return {
|
|
286
85
|
status: 500,
|
|
287
|
-
headers: {
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
88
|
+
}
|
|
288
89
|
};
|
|
289
90
|
}
|
|
290
91
|
}
|
|
291
92
|
return onAzureSwaRequest;
|
|
292
93
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
createQwikRouter
|
|
297
|
-
};
|
|
94
|
+
const createQwikCity = createQwikRouter;
|
|
95
|
+
|
|
96
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -29,6 +29,17 @@ export declare interface QwikRouterBunOptions extends ServerRenderOptions {
|
|
|
29
29
|
/** Set the Cache-Control header for all static files */
|
|
30
30
|
cacheControl?: string;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Provide a function that computes the origin of the server, used to resolve relative URLs and
|
|
34
|
+
* validate the request origin against CSRF attacks.
|
|
35
|
+
*
|
|
36
|
+
* When not specified, it defaults to the `ORIGIN` environment variable (if set).
|
|
37
|
+
*
|
|
38
|
+
* If `ORIGIN` is not set, it's derived from the incoming request, which is not recommended for
|
|
39
|
+
* production use.
|
|
40
|
+
*/
|
|
41
|
+
getOrigin?: (request: Request) => string | null;
|
|
42
|
+
/** Provide a function that returns a `ClientConn` for the given request. */
|
|
32
43
|
getClientConn?: (request: Request) => ClientConn;
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -1,85 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
_TextEncoderStream_polyfill,
|
|
8
|
-
mergeHeadersCookies,
|
|
9
|
-
requestHandler
|
|
10
|
-
} from "../request-handler/index.mjs";
|
|
11
|
-
import { extname, join } from "node:path";
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { _TextEncoderStream_polyfill, isStaticPath, getNotFound, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
import { join, extname } from 'node:path';
|
|
4
|
+
import { M as MIME_TYPES } from '../../chunks/mime-types.mjs';
|
|
5
|
+
import { isDev } from '@qwik.dev/core/build';
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
7
|
+
function getRequestUrl(request, opts) {
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
const origin = opts.getOrigin?.(request) ?? Bun.env.ORIGIN;
|
|
10
|
+
if (!origin) {
|
|
11
|
+
return url;
|
|
12
|
+
}
|
|
13
|
+
return new URL(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
|
+
}
|
|
66
15
|
function createQwikRouter(opts) {
|
|
67
|
-
var _a;
|
|
68
16
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
69
|
-
console.warn("qwikCityPlan is deprecated.
|
|
17
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
70
18
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
71
|
-
} else if (!opts.qwikRouterConfig) {
|
|
72
|
-
throw new Error("qwikRouterConfig is required.");
|
|
73
19
|
}
|
|
74
20
|
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
75
|
-
const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
|
|
76
21
|
if (opts.manifest) {
|
|
77
22
|
setServerPlatform(opts.manifest);
|
|
78
23
|
}
|
|
79
|
-
const staticFolder =
|
|
24
|
+
const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
80
25
|
async function router(request) {
|
|
81
26
|
try {
|
|
82
|
-
const url =
|
|
27
|
+
const url = getRequestUrl(request, opts);
|
|
83
28
|
const serverRequestEv = {
|
|
84
29
|
mode: "server",
|
|
85
30
|
locale: void 0,
|
|
@@ -106,11 +51,11 @@ function createQwikRouter(opts) {
|
|
|
106
51
|
return opts.getClientConn ? opts.getClientConn(request) : {};
|
|
107
52
|
}
|
|
108
53
|
};
|
|
109
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
54
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
110
55
|
if (handledResponse) {
|
|
111
|
-
handledResponse.completion.then((
|
|
112
|
-
if (
|
|
113
|
-
console.error(
|
|
56
|
+
handledResponse.completion.then((completion) => {
|
|
57
|
+
if (completion) {
|
|
58
|
+
console.error(completion);
|
|
114
59
|
}
|
|
115
60
|
});
|
|
116
61
|
const response = await handledResponse.response;
|
|
@@ -127,25 +72,34 @@ function createQwikRouter(opts) {
|
|
|
127
72
|
return null;
|
|
128
73
|
} catch (e) {
|
|
129
74
|
console.error(e);
|
|
130
|
-
return new Response(String(e || "Error"), {
|
|
75
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
131
76
|
status: 500,
|
|
132
|
-
headers: {
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
79
|
+
"X-Error": "bun-server"
|
|
80
|
+
}
|
|
133
81
|
});
|
|
134
82
|
}
|
|
135
83
|
}
|
|
136
84
|
const notFound = async (request) => {
|
|
137
85
|
try {
|
|
138
|
-
const url =
|
|
139
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
86
|
+
const url = getRequestUrl(request, opts);
|
|
87
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
140
88
|
return new Response(notFoundHtml, {
|
|
141
89
|
status: 404,
|
|
142
|
-
headers: {
|
|
90
|
+
headers: {
|
|
91
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
92
|
+
"X-Not-Found": url.pathname
|
|
93
|
+
}
|
|
143
94
|
});
|
|
144
95
|
} catch (e) {
|
|
145
96
|
console.error(e);
|
|
146
|
-
return new Response(String(e || "Error"), {
|
|
97
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
147
98
|
status: 500,
|
|
148
|
-
headers: {
|
|
99
|
+
headers: {
|
|
100
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
101
|
+
"X-Error": "bun-server"
|
|
102
|
+
}
|
|
149
103
|
});
|
|
150
104
|
}
|
|
151
105
|
};
|
|
@@ -155,7 +109,7 @@ function createQwikRouter(opts) {
|
|
|
155
109
|
let filePath;
|
|
156
110
|
if (fileName.includes(".")) {
|
|
157
111
|
filePath = join(staticFolder, pathname);
|
|
158
|
-
} else if (
|
|
112
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
159
113
|
filePath = join(staticFolder, pathname + "index.html");
|
|
160
114
|
} else {
|
|
161
115
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -166,15 +120,17 @@ function createQwikRouter(opts) {
|
|
|
166
120
|
};
|
|
167
121
|
};
|
|
168
122
|
const staticFile = async (request) => {
|
|
169
|
-
var _a2;
|
|
170
123
|
try {
|
|
171
|
-
const url =
|
|
124
|
+
const url = getRequestUrl(request, opts);
|
|
172
125
|
if (isStaticPath(request.method || "GET", url)) {
|
|
173
126
|
const { filePath, content } = await openStaticFile(url);
|
|
174
127
|
if (!await content.exists()) {
|
|
175
128
|
return new Response("Not Found", {
|
|
176
129
|
status: 404,
|
|
177
|
-
headers: {
|
|
130
|
+
headers: {
|
|
131
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
132
|
+
"X-Not-Found": url.pathname
|
|
133
|
+
}
|
|
178
134
|
});
|
|
179
135
|
}
|
|
180
136
|
const ext = extname(filePath).replace(/^\./, "");
|
|
@@ -182,16 +138,19 @@ function createQwikRouter(opts) {
|
|
|
182
138
|
status: 200,
|
|
183
139
|
headers: {
|
|
184
140
|
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
185
|
-
"Cache-Control":
|
|
141
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
186
142
|
}
|
|
187
143
|
});
|
|
188
144
|
}
|
|
189
145
|
return null;
|
|
190
146
|
} catch (e) {
|
|
191
147
|
console.error(e);
|
|
192
|
-
return new Response(String(e || "Error"), {
|
|
148
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
193
149
|
status: 500,
|
|
194
|
-
headers: {
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
152
|
+
"X-Error": "bun-server"
|
|
153
|
+
}
|
|
195
154
|
});
|
|
196
155
|
}
|
|
197
156
|
};
|
|
@@ -201,8 +160,6 @@ function createQwikRouter(opts) {
|
|
|
201
160
|
staticFile
|
|
202
161
|
};
|
|
203
162
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
createQwikRouter
|
|
208
|
-
};
|
|
163
|
+
const createQwikCity = createQwikRouter;
|
|
164
|
+
|
|
165
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
-
import {
|
|
7
|
-
_TextEncoderStream_polyfill,
|
|
8
|
-
mergeHeadersCookies,
|
|
9
|
-
requestHandler
|
|
10
|
-
} from "../request-handler/index.mjs";
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
import { isDev } from '@qwik.dev/core/build';
|
|
4
|
+
|
|
11
5
|
function createQwikRouter(opts) {
|
|
12
6
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
13
|
-
console.warn("qwikCityPlan is deprecated.
|
|
7
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
14
8
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
15
|
-
} else if (!opts.qwikRouterConfig) {
|
|
16
|
-
throw new Error("qwikRouterConfig is required.");
|
|
17
9
|
}
|
|
18
10
|
try {
|
|
19
11
|
new globalThis.TextEncoderStream();
|
|
20
|
-
} catch
|
|
12
|
+
} catch {
|
|
21
13
|
globalThis.TextEncoderStream = _TextEncoderStream_polyfill;
|
|
22
14
|
}
|
|
23
|
-
const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
|
|
24
15
|
if (opts.manifest) {
|
|
25
16
|
setServerPlatform(opts.manifest);
|
|
26
17
|
}
|
|
@@ -70,11 +61,11 @@ function createQwikRouter(opts) {
|
|
|
70
61
|
ctx
|
|
71
62
|
}
|
|
72
63
|
};
|
|
73
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
64
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
74
65
|
if (handledResponse) {
|
|
75
|
-
handledResponse.completion.then((
|
|
76
|
-
if (
|
|
77
|
-
console.error(
|
|
66
|
+
handledResponse.completion.then((completion) => {
|
|
67
|
+
if (completion) {
|
|
68
|
+
console.error(completion);
|
|
78
69
|
}
|
|
79
70
|
});
|
|
80
71
|
const response = await handledResponse.response;
|
|
@@ -85,23 +76,27 @@ function createQwikRouter(opts) {
|
|
|
85
76
|
return response;
|
|
86
77
|
}
|
|
87
78
|
}
|
|
88
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
79
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
89
80
|
return new Response(notFoundHtml, {
|
|
90
81
|
status: 404,
|
|
91
|
-
headers: {
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
84
|
+
"X-Not-Found": url.pathname
|
|
85
|
+
}
|
|
92
86
|
});
|
|
93
87
|
} catch (e) {
|
|
94
88
|
console.error(e);
|
|
95
|
-
return new Response(String(e || "Error"), {
|
|
89
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
96
90
|
status: 500,
|
|
97
|
-
headers: {
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
93
|
+
"X-Error": "cloudflare-pages"
|
|
94
|
+
}
|
|
98
95
|
});
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
return onCloudflarePagesFetch;
|
|
102
99
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
createQwikRouter
|
|
107
|
-
};
|
|
100
|
+
const createQwikCity = createQwikRouter;
|
|
101
|
+
|
|
102
|
+
export { createQwikCity, createQwikRouter };
|