Skip to content

Commit

Permalink
fix(vite): [dev proxy] sse not close
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Feb 4, 2025
1 parent ca5462c commit f7e3c52
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Agent } from 'node:http'
import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
Expand Down Expand Up @@ -81,6 +82,22 @@ export default defineConfig(({ mode }) => {
changeOrigin: true,
secure: false,
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()
})
},
},
},
},
Expand Down

0 comments on commit f7e3c52

Please sign in to comment.