@qwik.dev/router 2.0.0-beta.3 → 2.0.0-beta.31
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/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 +821 -0
- package/lib/chunks/system.mjs +333 -0
- package/lib/chunks/url.mjs +61 -0
- package/lib/chunks/use-functions.qwik.mjs +35 -0
- package/lib/chunks/worker-thread.qwik.mjs +2573 -0
- package/lib/index.d.ts +362 -142
- package/lib/index.qwik.mjs +949 -1244
- package/lib/middleware/aws-lambda/index.d.ts +0 -5
- package/lib/middleware/aws-lambda/index.mjs +14 -17
- package/lib/middleware/azure-swa/index.mjs +16 -221
- package/lib/middleware/bun/index.d.ts +11 -0
- package/lib/middleware/bun/index.mjs +50 -97
- package/lib/middleware/cloudflare-pages/index.mjs +22 -31
- package/lib/middleware/deno/index.d.ts +11 -0
- package/lib/middleware/deno/index.mjs +49 -97
- package/lib/middleware/firebase/index.mjs +6 -15
- package/lib/middleware/netlify-edge/index.mjs +22 -32
- package/lib/middleware/node/index.mjs +31 -105
- package/lib/middleware/request-handler/index.d.ts +163 -88
- package/lib/middleware/request-handler/index.mjs +1458 -1260
- package/lib/middleware/vercel-edge/index.mjs +27 -36
- 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
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Http2ServerRequest } from 'http2';
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
3
|
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
4
|
-
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
5
4
|
import type { QwikManifest } from '@qwik.dev/core/optimizer';
|
|
6
|
-
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
7
5
|
import type { Render } from '@qwik.dev/core/server';
|
|
8
6
|
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
9
7
|
import { ServerResponse } from 'http';
|
|
@@ -11,9 +9,6 @@ import { ServerResponse } from 'http';
|
|
|
11
9
|
declare interface AwsOpt {
|
|
12
10
|
render: Render;
|
|
13
11
|
manifest?: QwikManifest;
|
|
14
|
-
qwikRouterConfig: QwikRouterConfig;
|
|
15
|
-
/** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
|
|
16
|
-
qwikCityPlan?: QwikCityPlan;
|
|
17
12
|
}
|
|
18
13
|
|
|
19
14
|
/**
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
|
|
2
|
+
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
5
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
6
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
-
} else if (!opts.qwikRouterConfig) {
|
|
8
|
-
throw new Error("qwikRouterConfig is required.");
|
|
9
|
-
}
|
|
10
4
|
try {
|
|
11
|
-
const { router, staticFile, notFound } =
|
|
5
|
+
const { router, staticFile, notFound } = createQwikRouter$1({
|
|
12
6
|
render: opts.render,
|
|
13
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
14
7
|
manifest: opts.manifest,
|
|
15
8
|
static: {
|
|
16
9
|
cacheControl: "public, max-age=31557600"
|
|
@@ -23,7 +16,7 @@ function createQwikRouter(opts) {
|
|
|
23
16
|
}
|
|
24
17
|
});
|
|
25
18
|
const fixPath = (pathT) => {
|
|
26
|
-
if (
|
|
19
|
+
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
27
20
|
const url = new URL(pathT, "http://aws-qwik.local");
|
|
28
21
|
if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
|
|
29
22
|
return pathT;
|
|
@@ -43,13 +36,17 @@ function createQwikRouter(opts) {
|
|
|
43
36
|
});
|
|
44
37
|
});
|
|
45
38
|
};
|
|
46
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
fixPath,
|
|
41
|
+
router,
|
|
42
|
+
staticFile,
|
|
43
|
+
notFound,
|
|
44
|
+
handle
|
|
45
|
+
};
|
|
47
46
|
} catch (err) {
|
|
48
47
|
throw new Error(err.message);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
createQwikRouter
|
|
55
|
-
};
|
|
50
|
+
const createQwikCity = createQwikRouter;
|
|
51
|
+
|
|
52
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,216 +1,8 @@
|
|
|
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
|
-
));
|
|
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';
|
|
26
4
|
|
|
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
|
-
});
|
|
194
|
-
|
|
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
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
204
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
205
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
206
|
-
} else if (!opts.qwikRouterConfig) {
|
|
207
|
-
throw new Error("qwikRouterConfig is required.");
|
|
208
|
-
}
|
|
209
|
-
const qwikSerializer = {
|
|
210
|
-
_deserialize,
|
|
211
|
-
_serialize,
|
|
212
|
-
_verifySerializable
|
|
213
|
-
};
|
|
214
6
|
if (opts.manifest) {
|
|
215
7
|
setServerPlatform(opts.manifest);
|
|
216
8
|
}
|
|
@@ -238,7 +30,7 @@ function createQwikRouter(opts) {
|
|
|
238
30
|
status,
|
|
239
31
|
body: new Uint8Array(),
|
|
240
32
|
headers: {},
|
|
241
|
-
cookies: cookies.headers().map((header) =>
|
|
33
|
+
cookies: cookies.headers().map((header) => parseString(header))
|
|
242
34
|
};
|
|
243
35
|
headers.forEach((value, key) => response.headers[key] = value);
|
|
244
36
|
return new WritableStream({
|
|
@@ -262,7 +54,7 @@ function createQwikRouter(opts) {
|
|
|
262
54
|
};
|
|
263
55
|
}
|
|
264
56
|
};
|
|
265
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
57
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
266
58
|
if (handledResponse) {
|
|
267
59
|
handledResponse.completion.then((err) => {
|
|
268
60
|
if (err) {
|
|
@@ -274,24 +66,27 @@ function createQwikRouter(opts) {
|
|
|
274
66
|
return response;
|
|
275
67
|
}
|
|
276
68
|
}
|
|
277
|
-
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
69
|
+
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
278
70
|
return {
|
|
279
71
|
status: 404,
|
|
280
|
-
headers: {
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
74
|
+
"X-Not-Found": url.pathname
|
|
75
|
+
},
|
|
281
76
|
body: notFoundHtml
|
|
282
77
|
};
|
|
283
78
|
} catch (e) {
|
|
284
79
|
console.error(e);
|
|
285
80
|
return {
|
|
286
81
|
status: 500,
|
|
287
|
-
headers: {
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "text/plain; charset=utf-8"
|
|
84
|
+
}
|
|
288
85
|
};
|
|
289
86
|
}
|
|
290
87
|
}
|
|
291
88
|
return onAzureSwaRequest;
|
|
292
89
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
createQwikRouter
|
|
297
|
-
};
|
|
90
|
+
const createQwikCity = createQwikRouter;
|
|
91
|
+
|
|
92
|
+
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,26 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { isStaticPath } from
|
|
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 { isDev } from '@qwik.dev/core/build';
|
|
2
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
3
|
+
import { _TextEncoderStream_polyfill, isStaticPath, getNotFound, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
4
|
+
import { join, extname } from 'node:path';
|
|
5
|
+
import { M as MIME_TYPES, n as normalizeRequestUrl } from '../../chunks/url.mjs';
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
asx: "video/x-ms-asf",
|
|
19
|
-
avi: "video/x-msvideo",
|
|
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
|
|
66
|
-
function createQwikRouter(opts) {
|
|
67
|
-
var _a;
|
|
68
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
69
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
70
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
71
|
-
} else if (!opts.qwikRouterConfig) {
|
|
72
|
-
throw new Error("qwikRouterConfig is required.");
|
|
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;
|
|
73
12
|
}
|
|
13
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
|
+
}
|
|
15
|
+
function createQwikRouter(opts) {
|
|
74
16
|
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
75
|
-
const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
|
|
76
17
|
if (opts.manifest) {
|
|
77
18
|
setServerPlatform(opts.manifest);
|
|
78
19
|
}
|
|
79
|
-
const staticFolder =
|
|
20
|
+
const staticFolder = opts.static?.root ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
80
21
|
async function router(request) {
|
|
81
22
|
try {
|
|
82
|
-
const url =
|
|
23
|
+
const url = getRequestUrl(request, opts);
|
|
83
24
|
const serverRequestEv = {
|
|
84
25
|
mode: "server",
|
|
85
26
|
locale: void 0,
|
|
@@ -106,11 +47,11 @@ function createQwikRouter(opts) {
|
|
|
106
47
|
return opts.getClientConn ? opts.getClientConn(request) : {};
|
|
107
48
|
}
|
|
108
49
|
};
|
|
109
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
50
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
110
51
|
if (handledResponse) {
|
|
111
|
-
handledResponse.completion.then((
|
|
112
|
-
if (
|
|
113
|
-
console.error(
|
|
52
|
+
handledResponse.completion.then((completion) => {
|
|
53
|
+
if (completion) {
|
|
54
|
+
console.error(completion);
|
|
114
55
|
}
|
|
115
56
|
});
|
|
116
57
|
const response = await handledResponse.response;
|
|
@@ -127,25 +68,34 @@ function createQwikRouter(opts) {
|
|
|
127
68
|
return null;
|
|
128
69
|
} catch (e) {
|
|
129
70
|
console.error(e);
|
|
130
|
-
return new Response(String(e || "Error"), {
|
|
71
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
131
72
|
status: 500,
|
|
132
|
-
headers: {
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
75
|
+
"X-Error": "bun-server"
|
|
76
|
+
}
|
|
133
77
|
});
|
|
134
78
|
}
|
|
135
79
|
}
|
|
136
80
|
const notFound = async (request) => {
|
|
137
81
|
try {
|
|
138
|
-
const url =
|
|
139
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
82
|
+
const url = getRequestUrl(request, opts);
|
|
83
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
140
84
|
return new Response(notFoundHtml, {
|
|
141
85
|
status: 404,
|
|
142
|
-
headers: {
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
88
|
+
"X-Not-Found": url.pathname
|
|
89
|
+
}
|
|
143
90
|
});
|
|
144
91
|
} catch (e) {
|
|
145
92
|
console.error(e);
|
|
146
|
-
return new Response(String(e || "Error"), {
|
|
93
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
147
94
|
status: 500,
|
|
148
|
-
headers: {
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
97
|
+
"X-Error": "bun-server"
|
|
98
|
+
}
|
|
149
99
|
});
|
|
150
100
|
}
|
|
151
101
|
};
|
|
@@ -155,7 +105,7 @@ function createQwikRouter(opts) {
|
|
|
155
105
|
let filePath;
|
|
156
106
|
if (fileName.includes(".")) {
|
|
157
107
|
filePath = join(staticFolder, pathname);
|
|
158
|
-
} else if (
|
|
108
|
+
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
159
109
|
filePath = join(staticFolder, pathname + "index.html");
|
|
160
110
|
} else {
|
|
161
111
|
filePath = join(staticFolder, pathname, "index.html");
|
|
@@ -166,15 +116,17 @@ function createQwikRouter(opts) {
|
|
|
166
116
|
};
|
|
167
117
|
};
|
|
168
118
|
const staticFile = async (request) => {
|
|
169
|
-
var _a2;
|
|
170
119
|
try {
|
|
171
|
-
const url =
|
|
120
|
+
const url = getRequestUrl(request, opts);
|
|
172
121
|
if (isStaticPath(request.method || "GET", url)) {
|
|
173
122
|
const { filePath, content } = await openStaticFile(url);
|
|
174
123
|
if (!await content.exists()) {
|
|
175
124
|
return new Response("Not Found", {
|
|
176
125
|
status: 404,
|
|
177
|
-
headers: {
|
|
126
|
+
headers: {
|
|
127
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
128
|
+
"X-Not-Found": url.pathname
|
|
129
|
+
}
|
|
178
130
|
});
|
|
179
131
|
}
|
|
180
132
|
const ext = extname(filePath).replace(/^\./, "");
|
|
@@ -182,16 +134,19 @@ function createQwikRouter(opts) {
|
|
|
182
134
|
status: 200,
|
|
183
135
|
headers: {
|
|
184
136
|
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
185
|
-
"Cache-Control":
|
|
137
|
+
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
186
138
|
}
|
|
187
139
|
});
|
|
188
140
|
}
|
|
189
141
|
return null;
|
|
190
142
|
} catch (e) {
|
|
191
143
|
console.error(e);
|
|
192
|
-
return new Response(String(e || "Error"), {
|
|
144
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
193
145
|
status: 500,
|
|
194
|
-
headers: {
|
|
146
|
+
headers: {
|
|
147
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
148
|
+
"X-Error": "bun-server"
|
|
149
|
+
}
|
|
195
150
|
});
|
|
196
151
|
}
|
|
197
152
|
};
|
|
@@ -201,8 +156,6 @@ function createQwikRouter(opts) {
|
|
|
201
156
|
staticFile
|
|
202
157
|
};
|
|
203
158
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
createQwikRouter
|
|
208
|
-
};
|
|
159
|
+
const createQwikCity = createQwikRouter;
|
|
160
|
+
|
|
161
|
+
export { createQwikCity, createQwikRouter };
|
|
@@ -1,26 +1,13 @@
|
|
|
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
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
13
|
-
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
14
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
15
|
-
} else if (!opts.qwikRouterConfig) {
|
|
16
|
-
throw new Error("qwikRouterConfig is required.");
|
|
17
|
-
}
|
|
18
6
|
try {
|
|
19
7
|
new globalThis.TextEncoderStream();
|
|
20
|
-
} catch
|
|
8
|
+
} catch {
|
|
21
9
|
globalThis.TextEncoderStream = _TextEncoderStream_polyfill;
|
|
22
10
|
}
|
|
23
|
-
const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
|
|
24
11
|
if (opts.manifest) {
|
|
25
12
|
setServerPlatform(opts.manifest);
|
|
26
13
|
}
|
|
@@ -70,11 +57,11 @@ function createQwikRouter(opts) {
|
|
|
70
57
|
ctx
|
|
71
58
|
}
|
|
72
59
|
};
|
|
73
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
60
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
74
61
|
if (handledResponse) {
|
|
75
|
-
handledResponse.completion.then((
|
|
76
|
-
if (
|
|
77
|
-
console.error(
|
|
62
|
+
handledResponse.completion.then((completion) => {
|
|
63
|
+
if (completion) {
|
|
64
|
+
console.error(completion);
|
|
78
65
|
}
|
|
79
66
|
});
|
|
80
67
|
const response = await handledResponse.response;
|
|
@@ -85,23 +72,27 @@ function createQwikRouter(opts) {
|
|
|
85
72
|
return response;
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
75
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
89
76
|
return new Response(notFoundHtml, {
|
|
90
77
|
status: 404,
|
|
91
|
-
headers: {
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
80
|
+
"X-Not-Found": url.pathname
|
|
81
|
+
}
|
|
92
82
|
});
|
|
93
83
|
} catch (e) {
|
|
94
84
|
console.error(e);
|
|
95
|
-
return new Response(String(e || "Error"), {
|
|
85
|
+
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
96
86
|
status: 500,
|
|
97
|
-
headers: {
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
89
|
+
"X-Error": "cloudflare-pages"
|
|
90
|
+
}
|
|
98
91
|
});
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
return onCloudflarePagesFetch;
|
|
102
95
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
createQwikRouter
|
|
107
|
-
};
|
|
96
|
+
const createQwikCity = createQwikRouter;
|
|
97
|
+
|
|
98
|
+
export { createQwikCity, createQwikRouter };
|