Posted on :: 262 Words :: Tags: ,

Phoenix

Phoenix LiveView

OpenApi →

Counter App Error →

Solution for the following error:

17:08:15.791 [error] Could not check origin for Phoenix.Socket transport.

Origin of the request: http://<public_ip>:4000

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:

In config\runtime.exs , the port: parameter isn’t needed, the app uses 4000. And the important part, the host parameter needs brackets → [host: host] to work and the PHX_HOST env variable doesn’t have to be set, so that “0.0.0.0” is truthy and used as host:

#[...]
host = System.get_env("PHX_HOST") || "0.0.0.0"
port = String.to_integer(System.get_env("PORT") || "4000")

config :counter, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

config :counter, CounterWeb.Endpoint,
  url: [[host: host], scheme: "http"],
  http: [
    # Enable IPv6 and bind on all interfaces.
    # Set it to  {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
    # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
    # for details about using IPv6 vs IPv4 and loopback vs public addresses.
    ip: {0, 0, 0, 0, 0, 0, 0, 0},
    port: port
  ],
  secret_key_base: secret_key_base
#[...]

Now the app can be accessed with localhost:4000 and <public_ip>:4000