-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
50 lines (47 loc) · 1.77 KB
/
vite.config.ts
File metadata and controls
50 lines (47 loc) · 1.77 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
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { TanStackRouterVite } from '@tanstack/router-vite-plugin';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Use '' prefix to load all env vars (not just VITE_-prefixed ones)
const env = loadEnv(mode, process.cwd(), '');
console.log('API_KEY loaded:', env.API_KEY ? `[set, ${env.API_KEY.length} chars]` : 'MISSING');
if (mode === 'development' && !env.API_KEY) {
throw new Error('API_KEY is not set. Add it to your .env file (e.g. API_KEY=your-key).');
}
return {
plugins: [react(), TanStackRouterVite()],
server: {
proxy: env.API_KEY
? {
// All /v1 routes including WebSocket
'/v1': {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
configure: (proxy) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const p = proxy as any;
p.on('error', (err: Error) => {
console.log('proxy error', err);
});
p.on('proxyReq', (proxyReq: { setHeader: (k: string, v: string) => void }) => {
proxyReq.setHeader('X-API-Key', env.API_KEY);
});
p.on(
'proxyReqWs',
(
proxyReq: { setHeader: (k: string, v: string) => void },
req: { url: string }
) => {
console.log('WebSocket proxy request:', req.url);
proxyReq.setHeader('X-API-Key', env.API_KEY);
}
);
},
},
}
: undefined,
},
};
});