mirror of
https://github.com/algora-io/tv.git
synced 2025-03-17 20:17:45 +02:00
24 lines
686 B
Elixir
24 lines
686 B
Elixir
defmodule AlgoraWeb.Plugs.TransformDocs do
|
|
def init(options), do: options
|
|
|
|
def call(%Plug.Conn{} = conn, _ \\ []) do
|
|
conn
|
|
|> Plug.Conn.register_before_send(&transform_body/1)
|
|
|> Plug.Conn.update_req_header("accept-encoding", "identity", fn _ -> "identity" end)
|
|
end
|
|
|
|
def transform_body(%Plug.Conn{} = conn) do
|
|
proxy_url = Algora.config([:docs, :url])
|
|
|
|
body =
|
|
if conn.resp_body do
|
|
conn.resp_body
|
|
|> String.replace("src=\"/", "src=\"#{proxy_url}/")
|
|
|> String.replace("href=\"/", "href=\"#{proxy_url}/")
|
|
|> String.replace("#{proxy_url}", AlgoraWeb.Endpoint.url())
|
|
end
|
|
|
|
%Plug.Conn{conn | resp_body: body}
|
|
end
|
|
end
|