Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add logs message on deprecated routes (#1696)
- Loading branch information
Showing
3 changed files
with
34 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule AeMdwWeb.Plugs.DeprecationLoggerPlug do | ||
@moduledoc """ | ||
Logs useful information to detect deprecated endpoint clients. | ||
""" | ||
|
||
alias Plug.Conn | ||
alias AeMdw.Log | ||
|
||
require Logger | ||
|
||
@updated_prefixes ~w(status v2 v3) | ||
|
||
@spec init([]) :: [] | ||
def init(opts), do: opts | ||
|
||
@spec call(Conn.t(), []) :: Conn.t() | ||
def call(%Conn{path_info: [path_prefix | _rest]} = conn, _opts) | ||
when path_prefix in @updated_prefixes, | ||
do: conn | ||
|
||
def call(%Conn{request_path: request_path, remote_ip: remote_ip} = conn, _opts) do | ||
referer = | ||
case Conn.get_req_header(conn, "referer") do | ||
[referer] -> referer | ||
_no_match -> :inet.ntoa(remote_ip) | ||
end | ||
|
||
Log.info("[DEPRECATED] request: `#{request_path}`. referer: #{referer}") | ||
|
||
conn | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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