Open joshiste opened 4 years ago
I just figured out, if I disable the compression for the webpack dev server it works as expected...
I guess this is the culprit: https://github.com/expressjs/compression#server-sent-events
I just figured out, if I disable the compression for the webpack dev server it works as expected...
How do you perform it?
@Fractaliste I hacked this into my scripts:
"start": "sed -i '' -e 's/compress: true/compress: false/' ./node_modules/react-scripts/config/webpackDevServer.config.js && react-scripts start",
@joshiste Thanks man! You saved me a lot of time and frustration. I wouldn't have managed understanding this.
For those not using linux (sed
command unavailable) and using yarn
the following works using yarn patch protocol
yarn patch react-scripts
<path/to/folder>
):
➤ YN0000: Package react-scripts@npm:4.0.3 got extracted with success!
➤ YN0000: You can now edit the following folder: <path/to/folder>
➤ YN0000: Once you are done run yarn patch-commit "<path/to/folder>" and Yarn will store a patchfile based on your changes.
➤ YN0000: Done in 0s 436ms
config/webpackDevServer.config.js
- compress: true
+ compress: false
yarn patch-commit "<path/to/folder>" > ./react-scripts.diff
from your app's directory. This will generate the diff file react-scripts.diff
package.json
:
- "react-scripts": "^4.0.3",
+ "react-scripts": "patch:react-scripts@^4.0.3#./react-scripts.diff",
yarn
npm start
here might be the fix, at least only this works for me when I do redirect to another gateway
...
onProxyRes(proxyRes, req, res) {
if (req.headers.accept === 'text/event-stream') {
res.writeHead(res.statusCode, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-transform',
Connection: 'keep-alive',
});
proxyRes.pipe(res);
}
}
...
@michael-vasyliv Your fix is close, but not quite enough. I found the trick here :
res.writeHead(res.statusCode, { 'Content-Type': 'text/event-stream', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, no-transform', 'X-Accel-Buffering': 'no', 'Access-Control-Allow-Origin': '*' });
@michael-vasyliv Thanks for the fix! It works nice, but in my case resulted in duplicated messages to clients. I commented out this line:
proxyRes.pipe(res);
And that removed the duplicates 😄
It looks to me as the proxy has some issues with chunked encoding. This is my config:
This is the request/response from the backend (captured via wireshark)
and this is the request/response from the proxy:
The response looks somehow broken to me.