feat: Configure Vite proxy for API requests and update API URL to use a relative path.

This commit is contained in:
hissin 2025-11-20 15:12:57 +08:00
parent ff89fd1e87
commit 52e24c7f17
2 changed files with 12 additions and 1 deletions

View File

@ -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`, {

View File

@ -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/, '')
}
}
}
})