tporto
Could not check origin Phoenix LiveView
When accessing the page she tries to load lasts about 10 seconds and reloads again and stays in that loop without stopping. When accessing the server I saw that at each attempt it shows this message in the log:
[error] Could not check origin for Phoenix.Socket transport.
Origin of the request: http://www.autoplacasma.com.br
This happens when you are attempting a socket connection to
a different host than the one configured in your config/
files. For example, in development the host is configured
to “localhost” but you may be trying to access it from
“127.0.0.1”. To fix this issue, you may either:
- update [url: [host: …]] to your actual host in the
config file for your current environment (recommended)- pass the :check_origin option when configuring your
endpoint or when configuring the transport in your
UserSocket module, explicitly outlining which origins
are allowed:
check_origin: [“https://example.com”, “//another.com:888”, “//other.com”]
prod.exs
config :autoplacas, AutoplacasWeb.Endpoint,
http: [port: 80],
url: [host: "autoplacasma.com.br", port: 80],
check_origin: ["//autoplacasma.com.br"],
code_reloader: false,
cache_static_manifest: "priv/static/cache_manifest.json"
releases.exs
config :autoplacas, AutoplacasWeb.Endpoint,
http: [:inet6, port: 80],
secret_key_base: "mysecret",
server: true,
pubsub_server: Autoplacas.PubSub,
live_view: [signing_salt: "mysalt"]
Most Liked
KevinGenus
I’m late to the game, but using Phoenix v1.7.11 on Fly.io the following showed up in my logs:
This happens when you are attempting a socket connection to a different host than the one configured in your config/files. For example, in development the host is configured
to "localhost" but you may be trying to access it from "127.0.0.1". To fix this issue, you may either:
1. update [url: [host: ...]] to your actual host in the config file for your current environment (recommended)
2. pass the :check_origin option when configuring your endpoint or when configuring the transport in your UserSocket module, explicitly outlining which origins are allowed:
check_origin: ["https://example.com", "//another.com:888", "//other.com"]
I added check_origin: ["https://my_domain.com"] and it worked.
smahi
I have set check_origin in runtime.exs and the issue is gone. Thank you for every one
check_origin: ["//domain.ltd", "//sub1.domain.ltd"]
riccardomanfrin
I might be totally off track, but I think yours is the key question. Because I was fooled as well I’d like to elaborate:
From doc:
`:check_origin` - if the transport should check the origin of requests
when the `origin` header is present
Now the “origin” header from first random doc:
indicates the origin (scheme, hostname, and port) that **caused** the request
Caused… which is the website itself you connected to in the first place (ah-ah moment to me.. this explains why I find domain names in the “check_origin”!)
BUT assuming you have a config such this
config :mygoodservice, MyGoodService.Endpoint,
https: [
port: 8443,
...
],
url: [host: "mygoodservice.com"],
What is the proper origin? You are conveniently told that by the console error (which I got with the default check_origin: true config):
[error] Could not check origin for Phoenix.Socket transport.
Origin of the request: https://mygoodservice.com:8443
I suspect that just letting the default value true is not actually defaulting to the origin you are prompted about in the console
.. (maybe it’s forgetting the port? or I’m doing bad somwhere else… dunno).
Anyway setting the whole exact string reported by the console solved for me!
Also: if you are troubleshooting start/stop/restarting your service, I’d close the tab and open a new one.. for what is worth I’ve seen strange things happening on firefox (which might well be consequence of me doing this late night).
Cheers
Popular in Questions
Other popular topics
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









