ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - whatyouhide/corsica: Elixir library for dealing with CORS requests. 🏖
Elixir library for dealing with CORS requests. 🏖. Contribute to whatyouhide/corsica development by creating an account on GitHub.
Visit Site

GitHub - whatyouhide/corsica: Elixir library for dealing with CORS requests. 🏖

GitHub - whatyouhide/corsica: Elixir library for dealing with CORS requests. 🏖

Corsica

hex.pm badge Documentation badge CI Coverage Status

Corsica is a plug and a DSL for handling CORS requests. Documentation can be found online.

Landscape image of a sunset in Corsica, with the sea in the foreground and mountains in the background

Photo by Hendrik Cornelissen on Unsplash

(I had to include a nice pic because, let's be honest, CORS requests aren't the most fun thing in the world, are they?)

Features

  • Is compliant with the W3C CORS specification
  • Provides both low-level CORS utilities as well as high-level facilities (like a built-in plug and a CORS-focused router)
  • Handles preflight requests like a breeze
  • Never sends any CORS headers if the CORS request is not valid (smaller requests, yay!)

Installation

Add the :corsica dependency to your project's mix.exs:

defp deps do
  [
    {:plug, "~> 1.0"},
    {:corsica, "~> 2.0"}
  ]
end

and then run $ mix deps.get.

Overview

You can use Corsica both as a plug as well as a router generator. To use it as a plug, just plug it into your plug pipeline:

defmodule MyApp.Endpoint do
  plug Logger
  plug Corsica, origins: "http://foo.com"
  plug MyApp.Router
end

To gain finer control over which resources are CORS-enabled and with what options, you can use the Corsica.Router module:

defmodule MyApp.CORS do
  use Corsica.Router,
    origins: ["http://localhost", ~r{^https?://(.*\.)?foo\.com$}],
    allow_credentials: true,
    max_age: 600

  resource "/public/*", origins: "*"
  resource "/*"
end

defmodule MyApp.Endpoint do
  plug Logger
  plug MyApp.CORS
  plug MyApp.Router
end

This is only a brief overview of what Corsica can do. To find out more, head to the online documentation.

Common issues

Note that Corsica is compliant with the W3C CORS specification, which means CORS response headers are not sent for invalid CORS requests. The documentation goes into more detail about this, but it's worth noting so that the first impression is not that Corsica is doing nothing. One common pitfall is not including CORS request headers in your requests: this makes the request an invalid CORS request, so Corsica won't add any CORS response headers. Be sure to add at least the Origin header:

curl localhost:4000 -v -H "Origin: http://foo.com"

There is a dedicated page in the documentation that covers some of the common issues with CORS (and Corsica in part).

Contributing

If you find a bug, something unclear (including in the documentation!) or a behaviour that is not compliant with the latest revision of the official CORS specification, please open an issue on GitHub.

If you want to contribute to code or documentation, fork the repository and then open a Pull Request (how-to). Before opening a Pull Request, make sure all the tests passes by running $ mix test in your shell. If you're contributing to documentation, you can preview the generated documentation locally by running:

mix docs

Documentation will be generated in the doc/ directory.

License

MIT © 2015 Andrea Leopardi, see the license file.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory