Created
June 20, 2019 07:19
-
-
Save adanselm/95b77727d77caea81b26ffb1698a0caa to your computer and use it in GitHub Desktop.
Plug hook to do something before HTTP response is sent (like logging)
This file contains 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 MyApp.PlugRouter do | |
use Plug.Router | |
require Logger | |
plug Plug.Parsers, parsers: [:urlencoded, :multipart, :json], | |
pass: ["*/*"], | |
json_decoder: Poison | |
plug :match | |
plug :dispatch | |
put "/api/:file" do | |
conn | |
|> Plug.Conn.register_before_send(fn conn -> | |
Logger.info("#{inspect(conn)}") | |
conn | |
end) | |
|> Plug.Conn.put_resp_header("my-header", "something") | |
|> send_resp(200, "ok") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment