title: Enabling Cross-Origin Resource Sharing CORS in Phoenix / Elixir
body: <p>My frontend is a separate Brunch.io AngularJS app. Since my frontend runs on <a href="http://localhost:3333">http://localhost:3333</a> and my Phoenix backend on <a href="http://localhost:4000">http://localhost:4000</a> I get this error when trying to POST to <a href="http://localhost:4000/api/users/register">http://localhost:4000/api/users/register</a></p>
  
  <pre><code>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.
  </code></pre>
  
  <p>So I think it is a CORS issue. How can I send the headers in phoenix?</p>
  
  <p>This is my router.ex</p>
  
  <pre><code>  scope "/api", MyApp do
      pipe_through :api
      # Users
      post "/users/register", UserController, :register
    end
  </code></pre>
  
  <p>This is my UserController</p>
  
  <pre><code>defmodule MyApp.UserController do
    use MyApp.Web, :controller
  
    def register(conn, params) do
      IO.puts(inspect(params))
  
      conn
      |&gt; put_status(201)
      |&gt; json  %{ok: true, data: params}
    end
  
  end
  </code></pre>