Skip to content
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

sockjs: WebSocketSession not yet initialized #57

Closed
elijahiuu opened this issue Mar 20, 2016 · 8 comments · Fixed by #80
Closed

sockjs: WebSocketSession not yet initialized #57

elijahiuu opened this issue Mar 20, 2016 · 8 comments · Fixed by #80

Comments

@elijahiuu
Copy link

I am having problems proxying SockJS websockets. On the server side I am getting "WebSocketSession not yet initialized". On the client side I am getting "failed: Invalid frame header". It looks like it almost connects, but something goes wrong in handshake. Any ideas?

Here's my proxy configuration.

var gulp            = require('gulp');
var express         = require('express');
var proxyMiddleware = require('http-proxy-middleware');

gulp.task('serve', function() {
    proxy = proxyMiddleware('/go', {
        target: 'http://localhost:8080/',
        ws: true,
    });

    var app = express();
    app.use('/', express.static('./build/'));             
    app.use(proxy);                                       

    var server = app.listen(3000);
    server.on('upgrade', proxy.upgrade);                  
});

gulp.task('build', function(){
    gulp.src('src/**/*.*')
        .pipe(gulp.dest('./build/go/'));
});

Network tab:
General

Request URL:ws://localhost:3000/go/xxxxxxxxxx/websocket
Request Method:GET
Status Code:101 Switching Protocols

Response Headers

view source
connection:upgrade
date:Sun, 20 Mar 2016 20:59:11 GMT
sec-websocket-accept:sPIVWZeoUMNdIxL4EHnYgvBoZng=
sec-websocket-extensions:permessage-deflate;client_max_window_bits=15
server:Apache-Coyote/1.1
upgrade:websocket
@chimurai
Copy link
Owner

If your server is virtual hosted, try it with the option: changeOrigin: true

    proxy = proxyMiddleware('/go', {
        target: 'http://localhost:8080/',
        ws: true,
        changeOrigin: true
    });

@elijahiuu
Copy link
Author

It is a local Tomcat running a java app and hosting the socket. I tried changeOrigin, that gave me:

WebSocket connection to 'ws://localhost:3000/go/xxxxxxxxx/websocket' failed: Connection closed before receiving a handshake response 

@chimurai
Copy link
Owner

Maybe you can leave out ws:true from the options or set it to ws:false, since you are explicitly upgrading with server.on('upgrade', proxy.upgrade);

@elijahiuu
Copy link
Author

I think that actually works! Thank you @chimurai

@chimurai
Copy link
Owner

Glad to hear the solution works! :)

@chimurai
Copy link
Owner

@elijahiuu Now that I think about it, this might be a bug...

I'll have to spend some time to investigate this.

@chimurai chimurai added the bug label May 17, 2016
@chimurai chimurai reopened this May 17, 2016
@sashadt
Copy link

sashadt commented May 17, 2016

+1 Having same problem, and seeing:

WebSocket connection to 'ws://localhost:9000/pubsub' failed: Invalid frame header

removing the line ws: true from proxy options seems to fix it.

I agree it is either a bug, or usage documentation needs to be updated.

@chimurai
Copy link
Owner

@sashadt @elijahiuu

Think I've found the issue...

I published a beta version: v0.15.1-beta.
You can get it with: npm install http-proxy-middleware@0.15.1-beta

Can you test it to confirm the fix?

Problem shouldn't occur anymore when the following are used:

// proxy config
config.ws: true

// external upgrade
server.on('upgrade', proxy.upgrade); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants