Are query parameters supported? #45

Open
opened 2017-05-05 00:11:26 +00:00 by rcoenen · 1 comment
rcoenen commented 2017-05-05 00:11:26 +00:00 (Migrated from github.com)

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

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 2017-06-10 12:25:03 +00:00 (Migrated from github.com)

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 ?

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 `?`
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/nodejs-websocket#45
No description provided.