-
Notifications
You must be signed in to change notification settings - Fork 123
Ignore query parameters when attaching a websocket #271
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
Ignore query parameters when attaching a websocket #271
Conversation
|
Thanks 👍 |
|
Why to ignore query parameters when attaching a websocket? We use query parameters do determine the data in websokcet message. |
|
Hey @kevin10410, is this PR breaking your use case? Please describe it further for us to understand. |
|
Hi @sechel , We use parameters to determine the require data in websocket message like this.
We rollback to 8.0.5 currently. I was wondering ignored query parameters is necessary or not. Maybe you have another situation that need to ignore the query parameters? |
|
@kevin10410 what exactly do you mean by
What you would expect from a standard web server is that you reach the same server for the same route. The same holds true for WebSocket endpoints. Prior this PR different query parameters would define a new server with a separate configuration. |
|
In our websocket server, we determine the return message format by the query parameter works like different subprotocol
data: { 'id': 1, 'user': 'Kevin' }
data: { 'user': 'Kevin' } |
|
Ok, what you want to do is to configure your mock server for each connection like so: const server = new MockSocket('ws://test.dev/');
server.on('connection', socket => {
const url = new URL(socket.url);
const query = url.searchParams;
const fields = query.get('data').split(',');
// configure the socket according to the data value
socket.on('message', message => {
// for example, output a message for each message you get from the socket
// the format can now be determined by the fields values
});
});
// now you can connect multiple sockets
const s1 = new WebSocket('ws://test.dev/?data=id,user');
const s2 = new WebSocket('ws://test.dev/?data=user'); |
|
Yes, all url with query parameters would be transformed into the same url. |
Not sure if this is the best way to do it, happy to see comments.