Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite dev server not observing SSE close event from client #50

Open
abcd-ca opened this issue Feb 24, 2023 · 1 comment
Open

Vite dev server not observing SSE close event from client #50

abcd-ca opened this issue Feb 24, 2023 · 1 comment

Comments

@abcd-ca
Copy link

abcd-ca commented Feb 24, 2023

Hello, I have an expressjs back-end and a Vite dev server (running React) on the front-end. Have you encountered the issue where the close event from the client doesn't get triggered? I've inquired with Vite and with one of their dependency libraries, node-http-proxy. I don't think this is an issue with your library, it's lower level and probably with one of those 3rd parties but thought I'd ask.

http-party/node-http-proxy#921 (comment)

vitejs/vite#12157 (contains link to demo for the issue)

@yasumuo
Copy link

yasumuo commented Nov 13, 2023

I am not using this library, so it may be wrong to write here, but I was encountering the same problem as you, so I share the information.
I am using Go for the back-end, but the front-end is the same (running React on a vite dev server).
The close event of the client was not propagated to the back-end.
I added the following settings to vite.config.ts based on the comments you provided(http-party/node-http-proxy#921 (comment)), and now the close event is propagated to the back-end.
(The version of vite I am using is 4.3.0)

export default defineConfig({
  ...
  server: {
    proxy: {
      ...
      "/sse": {
        ...
        configure: (proxy, _options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            res.on("close", () => {
              if(!res.writableEnded) {
                proxyReq.destroy()
              }
            })
          })
        }
      }
    },
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants