Created
July 4, 2012 13:53
-
-
Save l4u/3047475 to your computer and use it in GitHub Desktop.
erlang cowboy 404 onresponse_hook
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
%% Hook for the above onresponse tests. | |
onresponse_hook(Status, Headers, Req) -> | |
case Status of | |
404 -> | |
{ok, Html} = file:read_file("www/404.html"), | |
{ok, Req2} = cowboy_http_req:reply(404, [], Html, Req), | |
Req2; | |
_ -> | |
Req | |
end. | |
cowboy:start_listener(http, 100, | |
cowboy_tcp_transport, [{port, config(http_port)}], | |
cowboy_http_protocol, [ | |
{dispatch, Dispatch}, | |
{onresponse, fun onresponse_hook/3} | |
] | |
), ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment