-
Notifications
You must be signed in to change notification settings - Fork 10
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
WebSocket support..? #2
Comments
That TODO item indicates that the Browser Sync socket is correctly proxied, It's not clear my bad. |
@shakyShane @simshanith I look at this and BrowserSync/browser-sync#71 (which was closed) but am still not clear on whether I can use BrowserSync with an app that uses socket.io. And there's nothing in the CHANGELOG of this or BrowserSync mentions about it. Basically I use Updated var bsync = require('browser-sync')
, proxyFactory = require('http-proxy')
var httpProxy = proxyFactory.createProxyServer({
target: {host: 'localhost', port: 3001},
ws: true // also fails if `false`
})
...
bsync({
startPath: '/',
browser: 'default',
port: 3000,
ui: { port: 9091},
server: {
baseDir: 'public',
middleware: [
function proxyApiRequests(req, res, next) {
if (/^\/api/i.test(req.url)) httpProxy.web(req, res)
else next()
}
]
}
}, function (err, bs) {
if (err) throw err
bs.server.on('upgrade', function (req, socket, head) {
if (/^\/api/i.test(req.url)) {
httpProxy.ws(req, socket, head)
}
})
}) |
@buunguyen By default, SocketIO requests go to "/socket.io/", so wouldn't get proxied by your custom middleware. Does your "backend server" also serve your Current BrowserSync proxy supports Socket.IO over XHR long-polling. With the snippet pasted in my original post opening this issue (#2), it could potentially proxy WebSockets as well. |
@simshanith thank you for your response. I've configured socket.io to use a custom path bs.server.on('upgrade', function (req, socket, head) {
if (/^\/api/i.test(req.url)) {
httpProxy.ws(req, socket, head)
}
}) The setup is essentially this:
With the provided snippet, API requests are proxied just fine. So are socket.io long-polling XHR requests, but not WS connections. Do you think it's possible to make WS work given the above setup? |
@buunguyen apologies for the significant delay in response. After returning to the issue, no, the above setup will not work. The above setup listens for the I'll see if I can get it working and draft a PR here. |
Ok, so a revision of the original synopsis. Looks like the |
Expose `upgrade` proxy handler on foxy `app` instance as `handleUpgrade` Attach `upgrade` listener in CLI server creation. Issue shakyShane#2
Expose `upgrade` proxy handler on foxy `app` instance as `handleUpgrade` Attach `upgrade` listener in CLI server creation. Issue shakyShane#2
Fixed in latest :) |
@simshanith 👍 thanks a lot for working on this. @shakyShane is this in browser-sync yet? I've just pulled 2.7.0, but still have the same error ("Connection closed before receiving a handshake response"). My usage is: gulp.task('sync', function (cb) {
bsync.init({
...
server: {
middleware: [
function (req, res, next) {
if (/^\/api/.test(req.url)) proxy.web(req, res, {target: 'http://localhost:3000'});
else next();
}
]
}
});
}) Do I need to perform WS |
As i am not sure if this is a foxy or BrowserSync problem, i opened an issue in the other project as well.: I apologize if that complicates things. |
The TODO checkbox is checked, but I don't see the expected code in index.js from looking at the nodejitsu/node-http-proxy docs...
The text was updated successfully, but these errors were encountered: