All Projects → whatyouhide → Corsica

whatyouhide / Corsica

Licence: mit
Elixir library for dealing with CORS requests. 🏖

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Corsica

dictator
Dictates what your users see. Plug-based authorization.
Stars: ✭ 77 (-79.36%)
Mutual labels:  plug
accent
Dynamically convert the case of your JSON API keys
Stars: ✭ 27 (-92.76%)
Mutual labels:  plug
Guardian
Elixir Authentication
Stars: ✭ 3,150 (+744.5%)
Mutual labels:  plug
gobang04
五子棋社区,前后端完全分离,SSM框架,CORS跨域访问,SSO单点登录,Bootstrap界面,RESTful构架风格,Netty即时通信,Token口令授权,Web端与客户端通信。异步请求,面向接口编程。
Stars: ✭ 14 (-96.25%)
Mutual labels:  cors
twitch-chat-visualizer
A Node.js Project. Would you like to see your chat stream with a custom design? This is for you!
Stars: ✭ 14 (-96.25%)
Mutual labels:  cors
getx template
Used to generate the template code of GetX framework | Flutter GetX模板代码生成(一个有用的IDEA插件)
Stars: ✭ 181 (-51.47%)
Mutual labels:  plug
BugHunter
No description or website provided.
Stars: ✭ 23 (-93.83%)
Mutual labels:  cors
Meiam.system
.NET 5 / .NET Core 3.1 WebAPI + Vue 2.0 + RBAC 企业级前后端分离权限框架
Stars: ✭ 340 (-8.85%)
Mutual labels:  cors
nextjs-cors
🎉 nextjs-cors is a node.js package to provide a Connect/Express middleware that can be used to enable CORS with various options 🚀
Stars: ✭ 97 (-73.99%)
Mutual labels:  cors
Blog.core
💖 ASP.NET Core 6.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
Stars: ✭ 3,542 (+849.6%)
Mutual labels:  cors
cors
Deno.js CORS middleware.
Stars: ✭ 46 (-87.67%)
Mutual labels:  cors
fasthttpcors
Cors Handler for fasthttp
Stars: ✭ 20 (-94.64%)
Mutual labels:  cors
Lumen Jwt
Lumen with JWT Authentication, Dingo API and CORS Support
Stars: ✭ 258 (-30.83%)
Mutual labels:  cors
SecExample
JAVA 漏洞靶场 (Vulnerability Environment For Java)
Stars: ✭ 228 (-38.87%)
Mutual labels:  cors
Xdomain
A pure JavaScript CORS alternative
Stars: ✭ 3,051 (+717.96%)
Mutual labels:  cors
plug heartbeat
A plug for responding to heartbeat requests.
Stars: ✭ 32 (-91.42%)
Mutual labels:  plug
plug rails cookie session store
Rails compatible Plug session store
Stars: ✭ 93 (-75.07%)
Mutual labels:  plug
Allorigins
👽 Pull contents from any page as JSON via API
Stars: ✭ 343 (-8.04%)
Mutual labels:  cors
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-20.91%)
Mutual labels:  cors
Cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
Stars: ✭ 266 (-28.69%)
Mutual labels:  cors

Corsica

Coverage Status Hex.pm

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

Nice Corsica pic (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

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

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

Ensure :corsica is started before your application (only if using :applications and not using application inference):

def application do
  [applications: [:corsica]]
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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].