From 9b9d3694e7aad03d1787c4df8503e02f8c9239ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erin=E2=80=84Yuki=E2=80=89Schlarb?= Date: Wed, 4 Sep 2024 16:19:11 +0000 Subject: [PATCH] Make WebSocket URL relative to path on which RustPad itself is served (#78) * Make WebSocket URL relative to path on which RustPad itself is served The path stays the same in all currently supported scenarios, but this also allows serving the app from a subpath. * Make generated Vite files use relative paths --- src/App.tsx | 8 +++----- vite.config.ts | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9a300e5..f97339a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -36,11 +36,9 @@ import Footer from "./Footer"; import User from "./User"; function getWsUri(id: string) { - return ( - (window.location.origin.startsWith("https") ? "wss://" : "ws://") + - window.location.host + - `/api/socket/${id}` - ); + let url = new URL(`api/socket/${id}`, window.location.href); + url.protocol = (url.protocol == "https:") ? "wss:" : "ws:"; + return url.href; } function generateName() { diff --git a/vite.config.ts b/vite.config.ts index 62a0a9b..4dec1d7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,6 +4,7 @@ import topLevelAwait from "vite-plugin-top-level-await"; import react from "@vitejs/plugin-react"; export default defineConfig({ + base: "", build: { chunkSizeWarningLimit: 1000, },