diff --git a/src/main.ts b/src/main.ts index f8b01d8..c5643c1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -182,14 +182,15 @@ electron.app.on("login", (event, webContents, request, authInfo, callback) => { event.preventDefault(); const parsedUrl = url.parse(request.url); - const host = `${parsedUrl.hostname}:${parsedUrl.port}`; - const auth = httpAuthByHosts[host]; + const port = parsedUrl.port != null ? parsedUrl.port : (parsedUrl.protocol === "https:" ? 443 : 80); + const hostnameAndPort = `${parsedUrl.hostname}:${port}`; + const auth = httpAuthByHosts[hostnameAndPort]; if (auth == null) { // Since this might race with the set-http-auth event above, // try again a second later setTimeout(() => { - const auth = httpAuthByHosts[host]; + const auth = httpAuthByHosts[hostnameAndPort]; if (auth == null) callback(null, null); else callback(auth.username, auth.password); }, 1000); diff --git a/src/renderer/tabs/openServer.ts b/src/renderer/tabs/openServer.ts index 8f64178..f86056d 100644 --- a/src/renderer/tabs/openServer.ts +++ b/src/renderer/tabs/openServer.ts @@ -78,9 +78,14 @@ function makeServerPane(serverEntry: ServerEntry) { retryButton.addEventListener("click", onRetryButtonClick); // Automatically add insecure protocol if none is already provided in the hostname - const protocol = serverEntry.hostname.startsWith("http") ? "" : "http://"; - const host = `${serverEntry.hostname}:${serverEntry.port}`; - const baseUrl = protocol + host; + const protocol = serverEntry.hostname.startsWith("https://") ? "https://" : "http://"; + + let hostname = serverEntry.hostname; + if (hostname.startsWith("http://")) hostname = hostname.substring("http://".length); + else if (hostname.startsWith("https://")) hostname = hostname.substring("https://".length); + const hostnameAndPort = `${hostname}:${serverEntry.port}`; + + const baseUrl = protocol + hostnameAndPort; function tryConnecting() { statusElt.textContent = i18n.t("common:server.connecting", { baseUrl }); @@ -141,10 +146,10 @@ function makeServerPane(serverEntry: ServerEntry) { paneElt.appendChild(webviewElt); webviewElt.focus(); - const buildHost = `${serverEntry.hostname}:${serverInfo.buildPort}`; + const buildHostnameAndPort = `${hostname}:${serverInfo.buildPort}`; const auth = { username: "superpowers", password: serverEntry.password }; - electron.ipcRenderer.send("set-http-auth", host, auth); - electron.ipcRenderer.send("set-http-auth", buildHost, auth); + electron.ipcRenderer.send("set-http-auth", hostnameAndPort, auth); + electron.ipcRenderer.send("set-http-auth", buildHostnameAndPort, auth); } tryConnecting();