tporto

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:

  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”]

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

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

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

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 :man_shrugging: .. (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

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement