Skip to content

Commit 4f73a0f

Browse files
authored
support using sslmode to set http vs https (#376)
* support using sslmode to set http vs https * cmt
1 parent cddf9ac commit 4f73a0f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

client/src/lib/helpers.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,25 @@ export const parseDgraphUrl = url => {
8080
const [host, queryString] = rest.split("?");
8181
const params = new URLSearchParams(queryString || "");
8282

83-
// Remove port number from host if present
84-
const hostWithoutPort = host.split(":")[0];
83+
// Get sslmode with default as 'disable'
84+
const sslmode = params.get("sslmode") || "disable";
85+
86+
// Only strip port for hypermode hosts
87+
const isHypermodeHost =
88+
host.includes("hypermode.host") ||
89+
host.includes("hypermode-stage.host");
90+
const hostWithoutPort = isHypermodeHost ? host.split(":")[0] : host;
91+
92+
// Use http for disable, https for others (require/verify-ca)
93+
const protocol = sslmode === "disable" ? "http" : "https";
94+
95+
const finalUrl = isHypermodeHost
96+
? `${protocol}://${hostWithoutPort}/dgraph`
97+
: `${protocol}://${host}`;
8598

8699
return {
87-
url: `https://${hostWithoutPort}/dgraph`,
88-
sslmode: params.get("sslmode"),
100+
url: finalUrl,
101+
sslmode,
89102
bearertoken: params.get("bearertoken"),
90103
};
91104
}

0 commit comments

Comments
 (0)