Giter VIP home page Giter VIP logo

Comments (12)

cherrydev avatar cherrydev commented on May 21, 2024 7

@chimurai I've verified that it works when you disable compression, but what it does not do is close the connection to the server when the client disconnects from an EventStream. I've tried it both with just closing the browser window and with cleaning up with eventStream.close(). I'm using http-proxy-middleware through the webpack dev server.

from http-proxy-middleware.

orszaczky avatar orszaczky commented on May 21, 2024 3

@chimurai Why is this closed? SSE is definitely not working over http-proxy-middleware.
I tested with a simple barebone setup (https://dev.to/4shub/building-with-server-sent-events-13j - only with express and http-proxy-middleware) and it's working without the middleware, but not working when I try to proxy.

Also every time the connection times out node logs out this message:
[HPM] Error occurred while trying to proxy request /stream-random-numbers from localhost:4000 to http://localhost:4040 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)

I can setup an example repo if needed, to demonstrate that messages are not arriving to the client

from http-proxy-middleware.

isabolic avatar isabolic commented on May 21, 2024 1

any example for SSE ?

from http-proxy-middleware.

chimurai avatar chimurai commented on May 21, 2024

@jmls Could you provide a sample setup showing this issue? Debugging it will be much faster.

Did you tried your setup with express + http-proxy-middleware to check if the same issue occurs. If it doesn't than it might be an issue browser-sync. If it also happens in that setup it might be an issue in http-proxy-middleware.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 21, 2024

Don't think this is a http-proxy-middleware issue.

Feel free to re-open this issue if you think it is a bug.

from http-proxy-middleware.

doejon avatar doejon commented on May 21, 2024

Just out of curiosity: Is there any way to set the keep alive timeout for proxy within webpack config?
When using SSE (EventSource) in combination with http-proxy-middleware, proxy disconnects SSE after 2 minutes (I assume it's the proxy's default keep-alive timeout).

Is there any flag I can set to avoid a SSE keep-alive-related disconnect?

devServer: {
    proxy: {
      '/api/*': {
        target: 'XYZ',
        secure: false,
        changeOrigin: true
      },[...]

from http-proxy-middleware.

chimurai avatar chimurai commented on May 21, 2024

I never used SSE...

But you can try to configure a custom agent and set the timeout accordingly.
https://nodejs.org/api/http.html#http_class_http_agent

You'll something like this:

const http = require('http');
var keepAliveAgent = new http.Agent({ keepAlive: true });

devServer: {
    proxy: {
      '/api/*': {
        target: 'XYZ',
        secure: false,
        changeOrigin: true,
        agent: keepAliveAgent
      },[...]

from http-proxy-middleware.

johnwebbcole avatar johnwebbcole commented on May 21, 2024

Has anyone made progress using eventSource requests through httlp-proxy-middleware? For my tests, the request works, but reconnection fails, even with the agent set as above.

from http-proxy-middleware.

andrecrimb avatar andrecrimb commented on May 21, 2024

Same problem.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 21, 2024

Here is an issue #371 in which compression module is causing issues. Maybe it's related to that.

A dozen of (mis)configuration can lead to a non-working setup.
Without a minimal working example (server + client) there is little to investigate.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 21, 2024

Verified proxying SSE is working with:
http://express-eventsource.herokuapp.com

const app = express();

app.use(createProxyMiddleware({
  target: 'http://express-eventsource.herokuapp.com',
  changeOrigin: true,
}));

app.listen(3000);

image

from http-proxy-middleware.

andrecrimb avatar andrecrimb commented on May 21, 2024

I'm using http-proxy-middleware in a React environment and I found out that the problem wasn't really with http-proxy-middleware, but somehow with how react is handling proxying by default with setupProxy.js.
I was able to bypass this EventSource "problem", creating a separated dev proxy file and proxying the React dev environment there.

      const express = require('express')
      const app = express()
      const { createProxyMiddleware } = require('http-proxy-middleware')
      
      app.use(
        '/api',
        createProxyMiddleware({
          secure: true,
          changeOrigin: true,
          target: 'http://your-api-url'
        })
      )
      
      const wsProxy = createProxyMiddleware({
        changeOrigin: true,
        target: 'http://localhost:3000',
        ws: true
      })
      app.use('/sockjs-node', wsProxy)
      
      app.use(
        '/',
        createProxyMiddleware({
          changeOrigin: true,
          target: 'http://localhost:3000'
        })
      )
      
      const server = app.listen(3001)
      
      server.on('upgrade', wsProxy.upgrade)

from http-proxy-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.