-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
executable file
·66 lines (63 loc) · 2.09 KB
/
Copy pathvite.config.js
File metadata and controls
executable file
·66 lines (63 loc) · 2.09 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
build: {
outDir: 'build',
},
server: {
port: 3020,
strictPort: true,
// usePolling is important in Docker / WSL environments where inotify
// events may not propagate from the host filesystem into the container.
watch: {
usePolling: true,
interval: 300,
},
proxy: {
'/api': {
target: 'http://127.0.0.1:5112',
changeOrigin: true,
secure: false,
// Handle ECONNREFUSED and other proxy errors gracefully so Vite
// never crashes and the log is not spammed when the FastAPI backend
// is temporarily unavailable (e.g. still starting up).
configure: (proxy) => {
proxy.on('error', (err, _req, res) => {
const code = err.code || ''
const isUnavailable =
code === 'ECONNREFUSED' ||
code === 'ECONNRESET' ||
code === 'ETIMEDOUT' ||
code === 'ENOTFOUND'
if (isUnavailable) {
// Only log once every 30 s to avoid console flood
if (!proxy._backendWarnedAt || Date.now() - proxy._backendWarnedAt > 30_000) {
console.warn('[vite:proxy] Backend at :5112 is not reachable — returning 503 until it starts')
proxy._backendWarnedAt = Date.now()
}
} else {
console.error('[vite:proxy] Unexpected proxy error:', err.message)
}
// Return a JSON 503 instead of letting Vite throw unhandled errors
if (res && !res.headersSent) {
try {
res.writeHead(503, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ error: 'Backend unavailable', code, status: 503 }))
} catch (_) { /* response already destroyed */ }
}
})
},
},
},
},
preview: {
port: 3020,
},
})