如何修复错误 'Could not check origin for Phoenix.Socket transport'? (凤凰 1.2.1)

How to fix error 'Could not check origin for Phoenix.Socket transport'? (Phoenix 1.2.1)

每当我访问 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:

我的 endpoint.ex

中有关注者
plug Plug.Session,
store: :cookie,
key: "_myapp_key",
signing_salt: "RHWasYaA",
domain: ".dev.myapp.me"

并关注我的 prod.exs

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

我也加入了 prod.exs

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

有什么办法可以解决这个问题?谢谢。

您应该在 check_origin 中添加所有解析到您的主机的域: check_origin: [..., "//team_abc.dev.myapp.me"]

编辑: 阅读 check_origin 功能的源代码后,似乎应该可以像这样设置通配符域名: check_origin: [..., "//*.myapp.me"]

更多详情:https://github.com/phoenixframework/phoenix/blob/da9f7653b9daf29a4c415be52a19ee6f4473e083/lib/phoenix/socket/transport.ex#L444