Created
February 10, 2020 15:03
-
-
Save gdotdesign/a1be133591f876126a08489a0196af5c to your computer and use it in GitHub Desktop.
Crystal Cors Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cors | |
include HTTP::Handler | |
getter origin : String | |
def initialize(@origin) | |
end | |
def call(context) | |
context.response.headers["Access-Control-Allow-Methods"] = "GET, PUT, POST, DELETE, LOAD, PATCH" | |
context.response.headers["Access-Control-Request-Headers"] = "Content-Type, *" | |
context.response.headers["Access-Control-Allow-Headers"] = "authorization" | |
context.response.headers["Access-Control-Allow-Origin"] = origin | |
context.response.headers["Access-Control-Allow-Credentials"] = "true" | |
context.response.headers["Access-Control-Max-Age"] = "1728000" | |
if context.request.method.downcase == "options" | |
context.response.content_type = "text/html; charset=utf-8" | |
context.response.status_code = 200 | |
context.response.print("") | |
else | |
call_next context | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment