Automatically upgrade to HTTPS in production
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2023-08-25 08:08:09 +02:00
parent 616c063d24
commit b9fae8e2aa
2 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,14 @@ export class APIClient {
return URL; return URL;
} }
/**
* Check out whether the backend is accessed through
* HTTPS or not
*/
static IsBackendSecure(): boolean {
return this.backendURL().startsWith("https");
}
/** /**
* Perform a request on the backend * Perform a request on the backend
*/ */

View File

@ -16,9 +16,18 @@ import { DarkThemeProvider } from "./hooks/context_providers/DarkThemeProvider";
import { SnackbarProvider } from "./hooks/context_providers/SnackbarProvider"; import { SnackbarProvider } from "./hooks/context_providers/SnackbarProvider";
import { AsyncWidget } from "./widgets/AsyncWidget"; import { AsyncWidget } from "./widgets/AsyncWidget";
import { LoadingMessageProvider } from "./hooks/context_providers/LoadingMessageProvider"; import { LoadingMessageProvider } from "./hooks/context_providers/LoadingMessageProvider";
import { APIClient } from "./api/ApiClient";
async function init() { async function init() {
try { try {
if (
APIClient.IsBackendSecure() &&
!window.location.href.startsWith("https") &&
window.location.hostname !== "localhost"
) {
window.location.href = window.location.href.replace("http:", "https:");
}
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement document.getElementById("root") as HTMLElement
); );