2015-11-05 119 views
7

我的前端是一個單獨的Brunch.io AngularJS應用程序。由於我的前端上http://localhost:3333運行和http://localhost:4000我的鳳凰後端我嘗試後到http://localhost:4000/api/users/register在Phoenix/Elixir中啓用跨源資源共享CORS

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時出現此錯誤。我如何在phoenix中發送標題?

這是我router.ex

scope "/api", MyApp do 
    pipe_through :api 
    # Users 
    post "https://stackoverflow.com/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 

回答