Fix getting remote IP behind reverse proxy
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -12,8 +12,14 @@ defmodule Mobilizon.Web.Auth.Context do
|
||||
opts
|
||||
end
|
||||
|
||||
def call(conn, _) do
|
||||
context = %{ip: to_string(:inet_parse.ntoa(conn.remote_ip))}
|
||||
def call(%{assigns: %{ip: _}} = conn, _opts), do: conn
|
||||
|
||||
def call(conn, _opts) do
|
||||
set_user_and_ip_in_context(conn)
|
||||
end
|
||||
|
||||
def set_user_and_ip_in_context(conn) do
|
||||
context = %{ip: conn.remote_ip |> :inet.ntoa() |> to_string()}
|
||||
|
||||
context =
|
||||
case Guardian.Plug.current_resource(conn) do
|
||||
|
||||
@@ -19,6 +19,12 @@ defmodule Mobilizon.Web.Endpoint do
|
||||
longpoll: false
|
||||
)
|
||||
|
||||
endpoint_config = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)
|
||||
|
||||
if Keyword.get(endpoint_config, :has_reverse_proxy, false) == true do
|
||||
plug(RemoteIp)
|
||||
end
|
||||
|
||||
plug(Mobilizon.Web.Plugs.UploadedMedia)
|
||||
|
||||
# Serve at "/" the static files from "priv/static" directory.
|
||||
|
||||
Reference in New Issue
Block a user