fixed the browser behavior for BackstageProtocolResolverFetchMiddleware

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2021-12-09 15:10:20 +01:00
parent 7927005152
commit afb7f31840
@@ -43,13 +43,18 @@ export class BackstageProtocolResolverFetchMiddleware
apply(next: FetchFunction): FetchFunction {
return async (input, init) => {
const request = new Request(input, init);
const { protocol, hostname, pathname, search, hash, username, password } =
new URL(request.url);
const prefix = 'backstage://';
if (protocol !== 'backstage:') {
if (!request.url.startsWith(prefix)) {
return next(input, init);
}
// Switch to a known protocol, since browser URL parsing misbehaves wildly
// on foreign protocols
const { hostname, pathname, search, hash, username, password } = new URL(
`http://${request.url.substring(prefix.length)}`,
);
let base = await this.discovery(hostname);
if (username || password) {
const baseUrl = new URL(base);