summaryrefslogtreecommitdiff
path: root/vite.config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vite.config.ts')
-rw-r--r--vite.config.ts31
1 files changed, 18 insertions, 13 deletions
diff --git a/vite.config.ts b/vite.config.ts
index 69d80d1..6f8126d 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,17 +1,22 @@
-import { defineConfig } from 'vite';
+import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
-// https://vitejs.dev/config/
-export default defineConfig({
- plugins: [react()],
- server: {
- proxy: {
- // Proxy /api requests to the backend server (running on port 3000 now)
- '/api': {
- target: 'http://localhost:3000', // Adjust to match backend PORT from .env
- changeOrigin: true, // Recommended for virtual hosted sites
- secure: false, // Don't verify SSL certs if backend uses self-signed cert in dev
+export default defineConfig(({ mode }) => {
+ const env = loadEnv(mode, process.cwd(), '');
+ const backendPort = env.PORT ?? '3001';
+ const backendTarget =
+ env.VITE_API_PROXY_TARGET ?? `http://localhost:${backendPort}`;
+
+ return {
+ plugins: [react()],
+ server: {
+ proxy: {
+ '/api': {
+ target: backendTarget,
+ changeOrigin: true,
+ secure: false,
+ },
},
},
- },
-}); \ No newline at end of file
+ };
+});