Skip to content

Commit

Permalink
Make WebSocket URL relative to path on which RustPad itself is served (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
ntninja authored Sep 4, 2024
1 parent c1cdd41 commit 9b9d369
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 9b9d369

Please sign in to comment.