5

I've tried to release my application with EXRM. The whole app is working except for WebSockets which fail to start

This is the error in the browser (Chrome)

WebSocket connection to 'ws://localhost:4001/socket/websocket?token=undefined' failed: Error during WebSocket handshake: Unexpected response code: 403

It seems that the variable token might be a problem. When starting with Mix phoenix.server it all works great. But released with commands:

$ mix deps.get
$ mix compile
$ MIX_ENV=prod mix digest
$ MIX_ENV=prod mix release
$ ./rel/project/bin/project

Might it be something regarding some missed steps of me or is it Phoenix related issue.

IgorekPotworek
  • 1,317
  • 13
  • 33
Krzysztof Wende
  • 3,208
  • 25
  • 38

1 Answers1

7

It seems that in prod.exs configuration file the url option is responsible for filtering the websocket connections to allow them only from the domain. Because of that it allows only connections from the set url, but not from any other including localhost.

So to test releases locally url has to be set to:

url: [host: "127.0.0.1", port: 4001],
Krzysztof Wende
  • 3,208
  • 25
  • 38
  • 1
    Yes, precisely. We must do an origin check so attackers cannot access your websocket from external pages. You should also have seen error reports in your terminal. – José Valim Sep 15 '15 at 17:39
  • Thanks! Been looking for this missing piece in the puzzle for days. – Jan Werkhoven Apr 20 '20 at 01:15