@zubra/router 6.0.5 → 6.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/answers.js +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/router",
3
- "version": "6.0.5",
3
+ "version": "6.0.6",
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",
package/src/answers.js CHANGED
@@ -15,10 +15,14 @@ export function checkedLocation({ location, external }, url) {
15
15
  throw new RouteError(`redirect() to ${JSON.stringify(location)}: not a URL`);
16
16
  }
17
17
  if (!['http:', 'https:'].includes(target.protocol)) throw new RouteError(`redirect() to a ${target.protocol} URL is refused`);
18
- if (target.origin !== url.origin && !external) throw new RouteError(`redirect() to ${target.origin}, another site: say redirect(to, { external: true }) if that's meant`);
18
+ // This host by http or https is this site: behind a proxy that ends TLS, the request's URL is
19
+ // http:// while the page is https://. It's written as a path, so the browser stays on the
20
+ // scheme it's on (an http:// location never takes an https page down to http).
21
+ const here = target.host === url.host;
22
+ if (!here && !external) throw new RouteError(`redirect() to ${target.origin}, another site: say redirect(to, { external: true }) if that's meant`);
19
23
  // A path on this site that begins `//` (from `https://site//evil.example`, `.//evil.example` or
20
24
  // `..//evil.example`) is protocol-relative in a Location header: one slash keeps it here.
21
- return target.origin === url.origin ? '/' + (target.pathname + target.search + target.hash).replace(/^[/\\]+/, '') : target.href;
25
+ return here ? '/' + (target.pathname + target.search + target.hash).replace(/^[/\\]+/, '') : target.href;
22
26
  }
23
27
 
24
28
  /** `return notFound()`: the path has nothing behind it (no such farm). The response is a 404. */