How do I fix the error "Failed to check origin for Phoenix.Socket transport"? (Phoenix 1.2.1)

Getting the following error while accessing https://team_abc.dev.myapp.me/

This issue might be specific for subdomains. Not very sure in what other contexts this issue arrises.

    07:26:06.498 [error] Could not check origin for Phoenix.Socket transport.

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

07:26:20.174 [error] Could not check origin for Phoenix.Socket transport.

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:

      

I have the following in endpoint.ex

plug Plug.Session,
store: :cookie,
key: "_myapp_key",
signing_salt: "RHWasYaA",
domain: ".dev.myapp.me"

      

and following in my prod.exs

http: [port: {:system, "PORT"}],
url: [host: "dev.myapp.me", port: 80]

      

I also added to prod.exs

config :myapp, MyApp.Endpoint,
check_origin: ["https://dev.myapp.me", "https://myapp.me"]

      

Any way to solve this problem? Thank.

+3


source to share


1 answer


You have to add all domains your host allows to check_origin: check_origin: [..., "//team_abc.dev.myapp.me"]

EDIT: After reading the source code for the check_origin function, it looks like it should be possible to set the wildcard domain name like this: check_origin: [..., "//*.myapp.me"]



More details: https://github.com/phoenixframework/phoenix/blob/da9f7653b9daf29a4c415be52a19ee6f4473e083/lib/phoenix/socket/transport.ex#L444

+7


source







All Articles