Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Add support for SSL servers by allowing to provide the protocol in th…
Browse files Browse the repository at this point in the history
…e hostname (and we fallback to http if none is provided)
  • Loading branch information
bilou84 committed Feb 19, 2018
1 parent e48cb33 commit 9c8cfee
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/renderer/tabs/openServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ function makeServerPane(serverEntry: ServerEntry) {
}
retryButton.addEventListener("click", onRetryButtonClick);

const host = serverEntry.hostname + (serverEntry.port != null ? `:${serverEntry.port}` : "");
// Automatically add insecure protocol if none is already provided in the hostname
const protocol = serverEntry.hostname.startsWith("http") ? "" : "http://";
const host = protocol + serverEntry.hostname + (serverEntry.port != null ? `:${serverEntry.port}` : "");

function tryConnecting() {
statusElt.textContent = i18n.t("common:server.connecting", { host });
retryButton.hidden = true;

fetch(`http://${host}/superpowers.json`, "json", onFetchJSON);
fetch(`${host}/superpowers.json`, "json", onFetchJSON);
}

function onFetchJSON(err: Error, serverInfo: { version: string; appApiVersion: number; }) {
Expand Down Expand Up @@ -126,7 +128,7 @@ function makeServerPane(serverEntry: ServerEntry) {
webviewElt.addEventListener("did-finish-load", onLoad);
webviewElt.addEventListener("did-fail-load", onError);

webviewElt.src = `http://${host}`;
webviewElt.src = host;
paneElt.appendChild(webviewElt);
webviewElt.focus();
}
Expand Down

0 comments on commit 9c8cfee

Please sign in to comment.