2015-11-05 9 views
7

Moja frontend jest oddzielną aplikacją Brunch.io AngularJS. Ponieważ moja nakładka działa na http://localhost:3333 i mój backend Phoenix na http://localhost:4000 otrzymuję ten błąd podczas próby Posta do http://localhost:4000/api/users/registerWłączanie udostępniania źródeł krzyżowych CORS w Phoenix/Elixir

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. 

Więc myślę, że jest to kwestia CORS. Jak mogę wysłać nagłówki w Phoenix?

To mój router.ex

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

To mój 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 

Odpowiedz