Skip to content

Instantly share code, notes, and snippets.

@mururu
mururu / ca_cowboy_middleware.erl
Last active March 28, 2018 08:05 — forked from sebmaynard/ca_cowboy_middleware.erl
[For Cowboy 2.0] A Cowboy middleware to set some CORS headers for every request, and to handle OPTIONS requests without needing to implement them in every handler.
-module(ca_cowboy_middleware).
-behaviour(cowboy_middleware).
-export([execute/2]).
execute(Req, Env) ->
{ok, ReqWithCorsHeaders} = set_cors_headers(Req),
Method = cowboy_req:method(ReqWithCorsHeaders),