Comments (12)
@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.
@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.
any example for SSE ?
from http-proxy-middleware.
@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.
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.
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.
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.
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.
Same problem.
from http-proxy-middleware.
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.
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);
from http-proxy-middleware.
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)
- req.url is always '/' HOT 4
- Fails to proxy from localhost to localhost HOT 2
- Too many subscriptions to Server.close event cause a OOM? HOT 4
- TS type compatibility HOT 4
- ERR_HTTP_HEADERS_SENT from onProxyReq with https-proxy-agent HOT 2
- Proxy to another proxy HOT 1
- Security Vulnerability in Dependency | follow-redirects HOT 2
- "Invalid context" error message is unhelpful when mixing paths with globs HOT 1
- Release plan for v3.0.0 HOT 1
- Response interceptor copyHeaders logic only removes first character of cookie domain because of non-greedy regex
- TypeError: (options.buffer || req).pipe is not a function HOT 1
- Allow custom Http Method like LIST HOT 3
- SSE close connection issue with proxy HOT 3
- V3: base path not stripped from WebSocket upgrade requests HOT 2
- SSL Error in when Upgrading from node 16 to 18 HOT 3
- Setting followRedirects to true limits the form-data body size length to 10 MB
- Removes port from target HOT 9
- Hono Support for http-proxy-middleware HOT 1
- The Cookie header is not being included in the redirected address. HOT 2
- How to reduce logger to only errors? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-proxy-middleware.