Vite runs inside the frontend container where 'localhost' resolves to the container itself, not the backend. Change the /api proxy target from http://localhost:8000 to http://backend:8000 so the request is routed to the backend service over the compose network.
26 lines
650 B
TypeScript
26 lines
650 B
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { resolve } from "path";
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
resolve: {
|
|
alias: {
|
|
"@": resolve(__dirname, "src"),
|
|
},
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
"/api": {
|
|
// In the dev compose stack the backend is reachable via its service
|
|
// name on the shared Docker/Podman network. Using "localhost" would
|
|
// resolve to the frontend container itself and cause ECONNREFUSED.
|
|
target: "http://backend:8000",
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
});
|