An Elixir Plug for adding Cross-Origin Resource Sharing (CORS) headers to web applications.
CorsPlug is an Elixir Plug middleware that adds Cross-Origin Resource Sharing (CORS) support to web applications. It configures and returns the necessary HTTP headers to allow controlled cross-origin requests, solving security and compatibility issues when APIs or frontends are served from different domains.
Elixir developers building web applications or APIs with Phoenix or other Plug-based frameworks that need to handle cross-origin requests from browsers.
Developers choose CorsPlug for its simplicity, seamless integration with Elixir's Plug ecosystem, and flexible configuration options that adhere to W3C standards, making it a reliable choice for CORS handling without manual header management.
An Elixir Plug to add CORS.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows origins as lists, regex patterns, or custom functions, enabling dynamic control, as shown in the configuration examples with strings and regexes.
Processes OPTIONS requests automatically, setting headers like Access-Control-Allow-Methods and Access-Control-Max-Age, reducing manual work.
Provides clear guidance for adding to Phoenix endpoints or pipelines, ensuring easy setup for Elixir web applications.
Offers the 'send_preflight_response?: false' option to disable automatic responses, allowing custom handling of OPTIONS requests.
The README warns that putting it in a pipeline won't work for unmatched routes, requiring manual OPTIONS route additions or endpoint placement, complicating setup.
Anonymous functions cannot be used for origin configuration due to quoting limitations, restricting inline dynamic logic without separate modules.
The author updates plug dependencies 'whenever I get around to,' which might lead to compatibility issues with newer Elixir or Plug versions.