2015-11-05 15 views
7

Il mio frontend è un'app separata di Brunch.io AngularJS. Dal momento che il mio frontend gira su http://localhost:3333 e il mio backend Phoenix http://localhost:4000 Ottengo questo errore quando si cerca di inviare messaggi in http://localhost:4000/api/users/registerAbilitazione di CORS di condivisione di origini incrociate in 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. 

quindi penso che è una questione CORS. Come posso inviare le intestazioni a Phoenix?

Questo è il mio router.ex

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

Questo è il mio 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 

risposta

Problemi correlati