-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
61 lines (55 loc) · 1.56 KB
/
Copy pathvite.config.js
File metadata and controls
61 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// import path from "path"
// import react from "@vitejs/plugin-react"
// import { defineConfig } from "vite"
// export default defineConfig({
// plugins: [react()],
// resolve: {
// alias: {
// "@": path.resolve(__dirname, "./src"),
// },
// },
// server: {
// proxy: {
// "/api": {
// target: "https://fastener-server.onrender.com",
// changeOrigin: true,
// secure: false,
// },
// },
// },
// })
import path from "path"
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const baseUrl = env.VITE_APP_BASE_URL || 'http://localhost:5000';
if (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) {
console.error(`Error: VITE_APP_BASE_URL must be a valid URL. Got: ${baseUrl}`);
process.exit(1);
}
console.log(`Mode: ${mode}, Proxy target: ${baseUrl}`);
return {
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
server: {
// port: 5174, // Fix the port to avoid random changes (5174 vs 5173)
proxy: {
'/api/v1': {
target: baseUrl,
changeOrigin: true,
secure: mode === 'production', // Use HTTPS in production
// No rewrite needed since backend expects /api/v1
},
},
},
define: {
'import.meta.env.VITE_APP_BASE_URL': JSON.stringify(baseUrl), // Expose to client
},
};
});