Qqwy
Phoenix channels over non-SSL
Hello everyone!
We’re building the seamless chat service Planga. (An official release will come soon!
)
Communication between the user’s browser with the other users is done through a Phoenix Channel (either using a websocket-connection or the fallback longpoll-transport).
Now, we’ve turned off CSRF-prevention checking, since any site is allowed to perform requests to the service (and it is then authenticated using their API key).
However, it seems that by default, Phoenix does not allow you to connect to websockets-over-ssl (wss:// as protocol) if the client application the user is visiting is a non-https website. The same is true for the longpoll transport (Phoenix disallows https://-based longpolling from a http website).
In development, where Phoenix runs without SSL itself, this is obviously not a problem, but since we’d like to allow developers that want to use our API to test things out with the system without them having to set up HTTPS certificates for their locally running development environments, we’d like to change this behaviour.
How can this behaviour be changed?
Most Liked
chrismccord
If I understand your issue correctly, this is not a phoenix thing, but a browser thing. Browsers will generally disallow mix content. For the phoenix.js client, if you leave off the protocol, it will inherit ws or wss based on the browser window’s protocol. Phoenix.js and the elixir channels side will gladly accept wss traffic. If you let the client inherit the protocol, ie let socket = new Socket("//yourhost.com/socket"). Provided your phoenix endpoint is configured for :http and :https then you are all set.
OvermindDL1
As I recall and that which a quick google search seems to confirm, an http page’s javascript can load wss websockets, but an https page’s javascript cannot load a ws websocket.
OvermindDL1
Popular in Questions
Other popular topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









