sitegui / nodejs-websocket

A node.js module for websocket server and client
MIT License
736 stars 155 forks source link

Are query parameters supported? #45

Open rcoenen opened 7 years ago

rcoenen commented 7 years ago

The WebSocket specification states that this is a valid websocket URI: ws://myserver.com/path?param=1

However I am unsure if nodejs-websocket supports access to the URI parameters.

Can anyone tell me if this is supported (and if yes, how to use it)?

Thanks

hlev commented 7 years ago

The Connection is passed as parameter to the "connection" listener, so you could do:

var ws = require("nodejs-websocket");

var server = ws.createServer(function (conn) {
    console.log(conn.path); // /path?param=1

        // ...
}).listen(8001)

But as far as I looked at the source, you would have to process the string yourself, there are no utility methods in the library itself.

You could use the querystring module of node's to parse the parameters after splitting the path on ?