This commit is contained in:
Daniel
2026-03-04 16:48:17 +08:00
parent 64f4c438c3
commit 26938449f0
34 changed files with 956 additions and 500 deletions

View File

@@ -22,11 +22,18 @@ export default defineConfig({
changeOrigin: true,
configure: (proxy) => {
proxy.on('error', () => {}) // 后端未启动时静默失败
// 抑制关标签/刷新时代理底层 socket 的 ECONNRESET避免刷屏
proxy.on('proxyReqWs', (proxyReq, req, socket, head) => {
socket?.on?.('error', () => {})
const out = (proxyReq as { socket?: { on?: (e: string, fn: () => void) => void } })?.socket
out?.on?.('error', () => {})
// 吞掉 ECONNRESET防止 Vite 打印 "ws proxy socket error"(关标签/刷新时常见)
function swallowEconnreset(s: { emit?: (ev: string, ...a: unknown[]) => boolean } | null) {
if (!s?.emit) return
const orig = s.emit.bind(s)
s.emit = function (ev: string, ...a: unknown[]) {
if (ev === 'error' && (a[0] as { code?: string })?.code === 'ECONNRESET') return false
return orig(ev, ...a)
}
}
proxy.on('proxyReqWs', (proxyReq, _req, socket, _head) => {
swallowEconnreset(socket ?? null)
swallowEconnreset((proxyReq as { socket?: unknown })?.socket ?? null)
})
},
},