From 52e24c7f17c413709e3489be7a232cdfd69cbff7 Mon Sep 17 00:00:00 2001 From: hissin Date: Thu, 20 Nov 2025 15:12:57 +0800 Subject: [PATCH] feat: Configure Vite proxy for API requests and update API URL to use a relative path. --- frontend/src/api.js | 4 +++- frontend/vite.config.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index 18992f1..9d38c8f 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1,6 +1,8 @@ import axios from 'axios'; -const API_URL = 'http://localhost:8000'; +// Use relative path '/api' which works with Nginx proxy in Docker +// and Vite proxy in local development +const API_URL = '/api'; export const generateCase = async (size, minVal, maxVal) => { const response = await axios.post(`${API_URL}/max_subarray/generate`, { diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 5a33944..34a09f8 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -4,4 +4,13 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api': { + target: 'http://localhost:8000', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '') + } + } + } })