Skip to content

Conversation

@sechel
Copy link
Contributor

@sechel sechel commented Jul 22, 2019

Not sure if this is the best way to do it, happy to see comments.

@thoov thoov merged commit 0026b6d into thoov:master Jul 24, 2019
@sechel
Copy link
Contributor Author

sechel commented Jul 24, 2019

Thanks 👍

@kevin10410
Copy link

Why to ignore query parameters when attaching a websocket?

We use query parameters do determine the data in websokcet message.

@sechel
Copy link
Contributor Author

sechel commented Aug 7, 2019

Hey @kevin10410, is this PR breaking your use case? Please describe it further for us to understand.

@kevin10410
Copy link

Hi @sechel ,

We use parameters to determine the require data in websocket message like this.

ws:url?data=var1,var2

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?

@sechel
Copy link
Contributor Author

sechel commented Aug 7, 2019

@kevin10410 what exactly do you mean by

require data in websocket message

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.

@kevin10410
Copy link

In our websocket server, we determine the return message format by the query parameter works like different subprotocol

ws:url?data=id,user

data: { 'id': 1, 'user': 'Kevin' }

ws:url?data=user

data: { 'user': 'Kevin' }

@sechel
Copy link
Contributor Author

sechel commented Aug 7, 2019

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');

@kevin10410
Copy link

Yes, all url with query parameters would be transformed into the same url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants