From 486e4fb6b8924369db54ab81d7a1e7d829587337 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Fri, 1 Aug 2025 15:54:52 -0500 Subject: [PATCH] test(ws): testing ws connection on the frontend --- frontend/src/WebSocketTest.tsx | 2 +- frontend/vite.config.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/frontend/src/WebSocketTest.tsx b/frontend/src/WebSocketTest.tsx index f617a7d..8b30563 100644 --- a/frontend/src/WebSocketTest.tsx +++ b/frontend/src/WebSocketTest.tsx @@ -8,7 +8,7 @@ const WebSocketViewer = () => { ws.current = new WebSocket( (window.location.protocol === "https:" ? "wss://" : "ws://") + window.location.host + - "/lst/api/logger/logs" + "/lst/ws" ); ws.current.onopen = () => { diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index ef8e03c..b3bd288 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,6 +1,13 @@ import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; +import path from "path"; +import dotenv from "dotenv"; +import { fileURLToPath } from "url"; +dotenv.config({ + path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.env"), +}); + // https://vite.dev/config/ export default defineConfig({ plugins: [react()], @@ -10,4 +17,24 @@ export default defineConfig({ assetsDir: "assets", emptyOutDir: true, }, + server: { + proxy: { + "/lst/api": { + target: `http://localhost:${Number( + process.env.VITE_SERVER_PORT || 8080 + )}`, + changeOrigin: true, + secure: false, + }, + "/lst/ws": { + target: `ws://localhost:${Number( + process.env.VITE_SERVER_PORT || 8080 + )}`, // Your Go WebSocket endpoint + ws: true, + changeOrigin: true, + secure: false, + rewrite: (path) => path.replace(/^\/ws/, ""), + }, + }, + }, });