加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在Phoenix / Elixir中启用跨源资源共享CORS

发布时间:2020-12-17 07:25:50 所属栏目:安全 来源:网络整理
导读:我的前端是一个单独的Brunch.io AngularJS应用程序.由于我的前端运行于 http://localhost:3333,而我的凤凰后端运行于 http://localhost:4000,因此在尝试POST到 http://localhost:4000/api/users/register时出现此错误 No 'Access-Control-Allow-Origin' head
我的前端是一个单独的Brunch.io AngularJS应用程序.由于我的前端运行于 http://localhost:3333,而我的凤凰后端运行于 http://localhost:4000,因此在尝试POST到 http://localhost:4000/api/users/register时出现此错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3333' is therefore not allowed access. The response had HTTP status code 404.

所以我认为这是一个CORS问题.如何在凤凰中发送标题?

这是我的router.ex

scope "/api",MyApp do
    pipe_through :api
    # Users
    post "/users/register",UserController,:register
  end

这是我的UserController

defmodule MyApp.UserController do
  use MyApp.Web,:controller

  def register(conn,params) do
    IO.puts(inspect(params))

    conn
    |> put_status(201)
    |> json  %{ok: true,data: params}
  end

end
你有几个选项可以为你连接起来:
https://hex.pm/packages?search=cors&sort=downloads

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读