franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 171 forks source link

How to configure socket.io? #123

Closed jazzyjeff5 closed 4 years ago

jazzyjeff5 commented 4 years ago

Sorry if this is explained in the documentation, I couldn't find it. ServerJS uses socket.io to handle websockets, right?

I need to configure maxHttpBufferSize to limit huge messages from being sent to my server, see:

https://socket.io/docs/server-api/

How do I set this parameter through ServerJS? Thanks!

franciscop commented 4 years ago

Woah, that seems to be not documented at all! Thanks for the issue.

socket.io is implemented as a plugin, which means that you might think this would work:

// Ideal, but does not work now
const options = {
  socket: { ... }
};
server(options, middleware);

Unfortunately options are not passed to the socket.io constructor currently:

// plugins/socket/index.js
ctx.io = socketIO(ctx.server);  // No options

Let me try to fix this

franciscop commented 4 years ago

It should be fixed now if you upgrade to the latest server 🎉

Could you please try it and let me know? See the example for some reference.

jazzyjeff5 commented 4 years ago

Works, thank you very much :D

franciscop commented 4 years ago

So happy to hear 🎉

Please let me know if you find any other issue. I'll leave this open until I can document the option later

franciscop commented 4 years ago

Added some basic docs to the website:

Socket Options

Please feel free to improve them! Documentation for this is here:

Options documentation

What value did you end up using for maxHttpBufferSize? That sounds like a good example for the docs.