fix(vite): [dev proxy] sse not close

This commit is contained in:
Jacky 2025-02-04 19:55:21 +08:00
parent ca5462c11d
commit f7e3c528c9
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D

View file

@ -1,3 +1,4 @@
import { Agent } from 'node:http'
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx' import vueJsx from '@vitejs/plugin-vue-jsx'
@ -81,6 +82,22 @@ export default defineConfig(({ mode }) => {
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
ws: true, ws: true,
timeout: 5000,
agent: new Agent({
keepAlive: false,
}),
onProxyReq(proxyReq, req) {
proxyReq.setHeader('Connection', 'keep-alive')
if (req.headers.accept === 'text/event-stream') {
proxyReq.setHeader('Cache-Control', 'no-cache')
proxyReq.setHeader('Content-Type', 'text/event-stream')
}
},
onProxyReqWs(proxyReq, req, socket) {
socket.on('close', () => {
proxyReq.destroy()
})
},
}, },
}, },
}, },