It gives me an extremely powerful GraphQL interface to my PostgreSQL databases. To handle incoming webSocket messages, you can follow the example in the ws server doc: wss.Brendan McKenzie Multiple WebSocket servers in a single Express instance What is your specific problem? Perhaps if you stated the specific problem you want help with, we could provide further assistance. If there was a better method to solve my problem That's just in how you choose to handle the incoming webSocket packets. You can create your own message handling within a webSocket message by creating a message name as part of the webSocket payload if you want (this is something that the socket.io layer on top of webSockets does for you), but it has nothing to do with Express at that point. There is no Express routing used for that. Once they are connected they stay connected and form a TCP pipe that you can send packets of data from client to server or from server to client. WebSockets connect on a particular path which you pass to the webSocketServer() constructor as it appears you already know. Your webSocket server can share an http server with Express, but that's pretty much all the two have to do with one another. That's not the proper architecture for webSockets. You do not use Express routers with webSockets. I have come across people recommending 'express-ws', but was wondering if there was a better method to solve my problem, specifically a method that does not involve other packages. This does work, but if it is possible to use routers with web-sockets, I think it would make my whole project much cleaner and more organised. I know that I can pass in the path when creating the WebSocketServer. (I click connect, nothing happens, I then click disconnect and connect again and it works.) I have tried using 'get' and 'post, but for some reason it only works after I try a second connection on postman. Router.?('/socket-endpoint', sNote) Īs you can see, I am unsure of what method to call on my router. Router.get('/get-notes/:id',jwtAuthentication, NotesController.getUserNotes) router.post('/create-note', jwtAuthentication, NotesController.createNote) I was trying to implement web-sockets (npm ws) in my express application, but got stuck on how I should implement my websockets so that they work with express router.Ĭurrently, my endpoints look like this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |