DEPRECATED: Please use Corsica instead

PlugCors DocumentationDownloads

A CORS Middleware for Plug.

Installation

Add the following to the deps section in your mix.exs file.

defp deps do
  [...
   {:plug_cors, "~> 0.7.3"}]
end

After you are done, run mix deps.get in your shell to fetch and compile PlugCors.

Usage

    plug PlugCors, origins: ["test.origin.test", "*.domain.com"], methods: ["GET", "POST"], headers: ["Authorization"]

If using with Phoenix, make sure to define the plug above your router. This is so the plug correctly responds to the OPTIONS requests the browser makes for CORS and prevents 404 responses to the browser’s CORS requests.

defmodule App.Endpoint do
  #the rest of the plugs defined in App.Endpoint

  plug PlugCors, origins: ["*"]
  plug :router, App.Router
end

You can also define the parameters inside of your elixir config if you wish. Parameters defined directly on the plug take precedence over the ones in config

  config :plug_cors,
    origins: ["test.origin.test", "*.domain.com"],
    methods: ["GET", "POST"],
    headers: ["Authorization"]

Parameters