Skip to content

Commit b525820

Browse files
fix: support websocket url configuration
1 parent 6da91ff commit b525820

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_WEBSOCKET_URL=

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
- `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash`
99
- `nvm install 22 && nvm use 22`
1010

11+
# Running locally
12+
13+
- Run `cp .env.example .env.local`
14+
- Run `npm run dev`
15+
1116
## Build
1217

1318
- Run `npm ci`

src/api/ws/ConnectionProvider.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ import {
1212
messageEventType,
1313
} from "./ConnectionContext";
1414

15+
const VITE_WEBSOCKET_URL = (
16+
import.meta.env.VITE_WEBSOCKET_URL as string
17+
).trim();
18+
1519
export function ConnectionProvider({ children }: PropsWithChildren) {
1620
const [ctxValue, _setCtxValue] = useState(defaultCtxValue);
1721
// connect to current host via websocket
18-
const websocketUrl = `${window.location.protocol.startsWith("https") ? "wss" : "ws"}://${window.location.hostname}:${window.location.port}/websocket`;
22+
const websocketUrl = VITE_WEBSOCKET_URL
23+
? VITE_WEBSOCKET_URL
24+
: `${window.location.protocol.startsWith("https") ? "wss" : "ws"}://${window.location.hostname}:${window.location.port}/websocket`;
1925

2026
const setSocketState = useSetAtom(socketStateAtom);
2127

0 commit comments

Comments
 (0)