Skip to content

Commit 53e5ba5

Browse files
committed
bugfix: ensureThatURLStartsWithHTTP for localhost
1 parent 8c53dbc commit 53e5ba5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

vis/js/utils/url.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,19 @@ const handleSelectPaper = (action: any) => {
102102

103103
const handleDeselectPaper = () => removeQueryParams("paper");
104104

105+
export const checkIsCurrentHostIsLocalhost = (): boolean => {
106+
const currentHost: string = window.location.host;
107+
return currentHost.startsWith("localhost");
108+
};
109+
105110
export const ensureThatURLStartsWithHTTP = (url: string): string => {
106111
let formattedURL = url;
107112

113+
const isCurrentHostIsLocalhost = checkIsCurrentHostIsLocalhost();
114+
const protocolToBeAdded = isCurrentHostIsLocalhost ? "http" : "https";
115+
108116
if (!/^https?:\/\//i.test(url)) {
109-
formattedURL = "https:" + url;
117+
formattedURL = `${protocolToBeAdded}:${url}`;
110118
}
111119

112120
return formattedURL;

0 commit comments

Comments
 (0)