-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
95 lines (93 loc) · 3.1 KB
/
Copy pathvite.config.js
File metadata and controls
95 lines (93 loc) · 3.1 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
const apiProxyTarget = process.env.VITE_API_PROXY_TARGET || 'http://localhost:8080'
// DeepSQL Agent chat service. The frontend reaches it at /agent-api/* which is
// rewritten to the agent's /* — a distinct prefix because both apps serve /api/*.
const agentProxyTarget = process.env.VITE_AGENT_PROXY_TARGET || 'http://localhost:8787'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
esbuild: {
loader: 'jsx',
include: /src\/.*\.(jsx?|tsx?)$/,
exclude: [],
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
},
build: {
outDir: 'dist',
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'charts': ['recharts'],
'editor': ['@monaco-editor/react'],
},
},
},
},
server: {
port: 3000,
open: false,
proxy: {
'/api': {
target: apiProxyTarget,
changeOrigin: true,
// LLM calls can take 60-120 s (multi-pass: schema + SQL + summarise).
// Default http-proxy timeout is 30 s — raise both ends to 5 min so the
// proxy never drops a connection before the backend finishes.
timeout: 300000,
proxyTimeout: 300000,
},
// Agent chat service: /agent-api/api/chat/stream → :8787/api/chat/stream
'/agent-api': {
target: agentProxyTarget,
// Keep the browser Host (localhost:3000) so Hermes CSRF Origin checks
// pass. changeOrigin:true rewrites Host to :8787 and profile/switch 403s.
changeOrigin: false,
rewrite: (p) => p.replace(/^\/agent-api/, ''),
timeout: 300000,
proxyTimeout: 300000,
// Production nginx stamps X-Remote-User via auth_request. Vite has no
// equivalent, so the browser sends the effective username (including
// impersonation). EventSource cannot set headers — remember the last
// value and attach it to SSE / other proxied calls.
configure: (proxy) => {
let lastRemoteUser
proxy.on('proxyReq', (proxyReq, req) => {
const incoming = req.headers['x-remote-user']
if (typeof incoming === 'string' && incoming.trim()) {
lastRemoteUser = incoming.trim()
}
try {
const url = new URL(req.url, 'http://vite.local')
const fromQuery = url.searchParams.get('remote_user')
if (fromQuery && fromQuery.trim()) {
lastRemoteUser = fromQuery.trim()
url.searchParams.delete('remote_user')
proxyReq.path = url.pathname + url.search
}
} catch {
/* keep lastRemoteUser */
}
if (lastRemoteUser) {
proxyReq.setHeader('X-Remote-User', lastRemoteUser)
}
})
},
},
},
},
})