@zubra/router 5.17.0 → 5.18.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/package.json +3 -3
- package/src/index.js +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zubra/router",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.0",
|
|
4
4
|
"description": "Serve Zubra components that say 'use route <path>' as pages, with a server-only load, for apps with no host framework.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"urlpattern-polyfill": "10.1.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@zubra/compiler": "^5.
|
|
26
|
-
"@zubra/server": "^5.
|
|
25
|
+
"@zubra/compiler": "^5.18.0",
|
|
26
|
+
"@zubra/server": "^5.18.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@zubra/compiler": "file:../compiler",
|
package/src/index.js
CHANGED
|
@@ -334,9 +334,21 @@ function rewriteImports(code, to) {
|
|
|
334
334
|
return code.replace(/(\bfrom\s*|\bimport\s*\(?\s*)(['"])(\.{1,2}\/[^'"]+)\2/g, (_, keyword, quote, specifier) => `${keyword}${quote}${to(specifier)}${quote}`);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
// A Host header is a host and an optional port. Anything else (a path, a query, an empty one)
|
|
338
|
+
// would move the URL's path away from the request's: `Host: site/admin` with `GET /public` would
|
|
339
|
+
// read as `/admin/public`, past a proxy that allowed `/public`. That's refused (the callers answer
|
|
340
|
+
// 400); a request without one (HTTP/1.0) is for localhost.
|
|
341
|
+
const HOST = /^(?:[\w.-]+|\[[\da-fA-F:.]+\])(?::\d{1,5})?$/;
|
|
342
|
+
const hostOf = (req) => {
|
|
343
|
+
const { host } = req.headers;
|
|
344
|
+
if (host === undefined) return 'localhost';
|
|
345
|
+
if (!HOST.test(host)) throw new TypeError(`not a host: ${JSON.stringify(host)}`);
|
|
346
|
+
return host;
|
|
347
|
+
};
|
|
348
|
+
|
|
337
349
|
/** A Node GET or HEAD request as a fetch Request. */
|
|
338
350
|
function toRequest(req) {
|
|
339
|
-
const host = req
|
|
351
|
+
const host = hostOf(req);
|
|
340
352
|
const protocol = req.socket?.encrypted ? 'https' : 'http';
|
|
341
353
|
const headers = new Headers();
|
|
342
354
|
for (const [name, value] of Object.entries(req.headers)) {
|