diff --git a/frontend/src/lib/api.js b/frontend/src/lib/api.js index 2ce5b67..5a48db7 100644 --- a/frontend/src/lib/api.js +++ b/frontend/src/lib/api.js @@ -1,7 +1,5 @@ -const BASE = import.meta.env.VITE_API_URL || 'http://localhost:3000'; - export async function api(path, options = {}) { - const res = await fetch(`${BASE}/api/v1${path}`, { + const res = await fetch(`/api/v1${path}`, { credentials: 'include', headers: { 'Content-Type': 'application/json', diff --git a/frontend/src/lib/sse.js b/frontend/src/lib/sse.js index 990f067..e867c45 100644 --- a/frontend/src/lib/sse.js +++ b/frontend/src/lib/sse.js @@ -1,7 +1,5 @@ -const BASE = import.meta.env.VITE_API_URL || 'http://localhost:3000'; - export function openEventStream(handlers) { - const url = `${BASE}/api/v1/events`; + const url = `/api/v1/events`; const source = new EventSource(url, { withCredentials: true }); for (const [event, handler] of Object.entries(handlers)) { diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 93ea31e..d0f669f 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,7 +1,19 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; -export default defineConfig({ - plugins: [react()], - server: { port: 5173 }, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ''); + + return { + plugins: [react()], + server: { + port: 5173, + proxy: { + '/api': { + target: env.VITE_API_URL || 'http://localhost:3000', + changeOrigin: true, + }, + }, + }, + }; });