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

Proxy Buffers EventSources #3391

Closed
DeedleFake opened this Issue Nov 2, 2017 · 5 comments

Comments

Projects
None yet
6 participants
@DeedleFake

DeedleFake commented Nov 2, 2017

Is this a bug report?

Yes.

Can you also reproduce the problem with npm 4.x?

Yes.

Environment

  1. node -v: v8.8.1
  2. npm -v: 5.5.1
  3. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.16

Then, specify:

  1. Operating system: Arch Linux
  2. Browser and version (if relevant): Firefox 57.0b13

Steps to Reproduce

I've got an existing app that I'd like to rewrite using React. The app has a Go backend that provides an EventSource endpoint. I attempted to use the proxy functionality of the development server to route requests for the endpoint to the Go backend.

Example Backend:

func handleEvents(rw http.ResponseWriter, req *http.Request) {
  rw.Header().Set("Content-Type", "text/event-stream")

  for i := 0; true; i++ {
    _, err := fmt.Fprintf(rw, "data: %v\n\n")
    if err != nil {
      break
    }
    rw.(http.Flusher).Flush()
  }
}

Example Frontend:

let es = new EventSource('/events');
es.onmessage = (msg) => {
  console.log(msg);
};

Expected Behavior

It should print a list of numbers in the browser console.

Actual Behavior

Nothing happens at all until I kill the Go backend process, at which point all of the events that the backend had sent arrive suddenly all at once. The EventSource also occasionally calls its onerror callback and then disconnects suddenly for no apparent reason.

Note also that the code works completely fine if I serve the files produced by npm run build directly from the Go backend.

@gaearon gaearon added the issue: bug label Nov 3, 2017

@duhrich

This comment has been minimized.

duhrich commented Nov 29, 2017

Have you come up with any workarounds in the meantime? Having the same issue...

@gaearon

This comment has been minimized.

Member

gaearon commented Jan 8, 2018

We're happy to take fixes for this if you have suggestions.

@bogdan-calapod

This comment has been minimized.

bogdan-calapod commented Feb 20, 2018

After lurking around the internet having the same problem, I think this is related to #966. I think an ok fix would be to toggle webpack dev server's compression via an ENV variable of some kind.

A workaround might be to enable CORS on the SSE server and connect to it directly

@Downchuck

This comment has been minimized.

Downchuck commented May 15, 2018

I think the fix recommended was to set Cache-Control in the SSE headers.
#1633

@stale

This comment has been minimized.

stale bot commented Nov 2, 2018

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.

@stale stale bot added the stale label Nov 2, 2018

@Timer Timer closed this Nov 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment