From afb7f31840d506c270035d1b53e5f4ede553e1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 9 Dec 2021 15:10:20 +0100 Subject: [PATCH] fixed the browser behavior for BackstageProtocolResolverFetchMiddleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../BackstageProtocolResolverFetchMiddleware.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core-app-api/src/apis/implementations/FetchApi/BackstageProtocolResolverFetchMiddleware.ts b/packages/core-app-api/src/apis/implementations/FetchApi/BackstageProtocolResolverFetchMiddleware.ts index 03d08c3096..2144d0058d 100644 --- a/packages/core-app-api/src/apis/implementations/FetchApi/BackstageProtocolResolverFetchMiddleware.ts +++ b/packages/core-app-api/src/apis/implementations/FetchApi/BackstageProtocolResolverFetchMiddleware.ts @@ -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);