0

I'm trying to host a websocket server on my heroku app. Everything works fine on localhost, but when I upload it to Heroku, i only get 404 errors, you can try by yourself : wss://ethyme-api.herokuapp.com/
So what is the path to the server ?

1

Your WS path looks good to me it may an issue on the server side.

Here's how I build the WS URL on the client side to run on local and Heroku:

const wsUrl = (window.location.protocol === 'http:' ? 'ws://' : 'wss://') + window.location.host;
| improve this answer | |
  • mh I can't do this, my api isnt hosted on the same domain as my website. Here is how I create the websocket server : const server = http.createServer(app); /* express app */ const wss = new Server({ server }); /* from ws */ and then const port = parseInt(process.env.PORT) | 8000; server.listen(port, () => console.log(`Serveur WebSocket prêt sur le port ${(server['address']() as any).port}`)) – Jacques Feb 19 at 17:20
  • I don't think that your WS server is running. You should call the WebSocket Server constructor AFTER listening with Express. – POZ Feb 19 at 17:34
  • mmm this doesnt change anything – Jacques Feb 19 at 18:22
  • are the logs normal ? 2020-02-19T18:27:30.261142+00:00 heroku[router]: at=info method=GET path="/" host=ethyme-api.herokuapp.com request_id=d6c0e965-ca39-4b76-bfd8-6aa5c35f377b fwd="77.204.130.110" dyno=web.1 connect=1ms service=3ms status=404 bytes=420 protocol=https – Jacques Feb 19 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.