Created
January 11, 2016 12:58
-
-
Save luizpvas/d12b986a42eac6267e7a to your computer and use it in GitHub Desktop.
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
defmodule MyRouter do | |
use Plug.Router | |
# Starts the server | |
def start do | |
Plug.Adapters.Cowboy.http MyRouter, [] | |
end | |
plug :my_handle # custom plug | |
plug :match | |
plug :dispatch | |
def my_handle(conn, _opts) do | |
Plug.Conn.register_before_send(conn, fn conn -> | |
# Doesn't show up in console. | |
IO.puts "== cleaning up ==" | |
conn | |
end) | |
# This is printed to the console. | |
IO.puts "== setting up ==" | |
conn | |
end | |
get "/" do | |
send_resp(conn, 200, "world") | |
end | |
match _ do | |
send_resp(conn, 404, "oops") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment