2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Endpoint do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2018-10-11 17:37:39 +02:00
|
|
|
Endpoint for Mobilizon app
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2021-06-27 13:15:24 +02:00
|
|
|
|
2022-09-21 10:15:28 +02:00
|
|
|
if Application.compile_env(:mobilizon, :env) !== :test do
|
2021-02-08 11:52:16 +01:00
|
|
|
use Sentry.PlugCapture
|
|
|
|
end
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
use Phoenix.Endpoint, otp_app: :mobilizon
|
2019-12-03 11:29:51 +01:00
|
|
|
use Absinthe.Phoenix.Endpoint
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2023-11-15 18:15:21 +01:00
|
|
|
# Serve at "/" the static files from "priv/static" directory.
|
|
|
|
#
|
|
|
|
# You should set gzip to true if you are running phoenix.digest
|
|
|
|
# when deploying your static files in production.
|
|
|
|
plug(
|
|
|
|
Plug.Static,
|
|
|
|
at: "/",
|
|
|
|
from: {:mobilizon, "priv/static"},
|
|
|
|
gzip: false,
|
|
|
|
only: Mobilizon.Web.static_paths()
|
|
|
|
# only_matching: ["precache-manifest"]
|
|
|
|
)
|
|
|
|
|
|
|
|
plug(Mobilizon.Web.Plugs.UploadedMedia)
|
|
|
|
|
2021-07-27 19:47:54 +02:00
|
|
|
plug(Mobilizon.Web.Plugs.DetectLocalePlug)
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2022-09-21 08:53:50 +02:00
|
|
|
if Application.compile_env(:mobilizon, :env) !== :dev do
|
2021-02-24 19:06:48 +01:00
|
|
|
plug(Mobilizon.Web.Plugs.HTTPSecurityPlug)
|
|
|
|
end
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2019-10-05 19:07:50 +02:00
|
|
|
# For e2e tests
|
2021-09-10 11:34:26 +02:00
|
|
|
# if Application.get_env(:mobilizon, :sql_sandbox) do
|
|
|
|
# plug(Phoenix.Ecto.SQL.Sandbox,
|
|
|
|
# at: "/sandbox",
|
|
|
|
# header: "x-session-id",
|
|
|
|
# repo: Mobilizon.Storage.Repo
|
|
|
|
# )
|
|
|
|
# end
|
2019-10-05 19:07:50 +02:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
socket("/graphql_socket", Mobilizon.Web.GraphQLSocket,
|
2019-12-03 11:29:51 +01:00
|
|
|
websocket: true,
|
|
|
|
longpoll: false
|
|
|
|
)
|
|
|
|
|
2022-09-21 10:15:47 +02:00
|
|
|
plug(Unplug,
|
|
|
|
if:
|
|
|
|
{Mobilizon.Service.UnplugPredicates.AppConfigKeywordEquals,
|
|
|
|
{:mobilizon, Mobilizon.Web.Endpoint, :has_reverse_proxy, false, true}},
|
|
|
|
do: RemoteIp
|
|
|
|
)
|
2020-08-27 15:42:09 +02:00
|
|
|
|
2017-12-08 09:58:14 +01:00
|
|
|
# Code reloading can be explicitly enabled under the
|
|
|
|
# :code_reloader configuration of your endpoint.
|
|
|
|
if code_reloading? do
|
2018-07-27 10:45:35 +02:00
|
|
|
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
|
|
|
|
plug(Phoenix.LiveReloader)
|
|
|
|
plug(Phoenix.CodeReloader)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
plug(CORSPlug)
|
|
|
|
plug(Plug.RequestId)
|
|
|
|
plug(Plug.Logger)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2022-10-06 08:59:50 +02:00
|
|
|
plug(Replug,
|
|
|
|
plug: {Plug.Parsers, pass: ["*/*"], json_decoder: Jason},
|
|
|
|
opts: {Mobilizon.Web.PlugConfigs, :parsers}
|
2018-07-27 10:45:35 +02:00
|
|
|
)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
plug(Plug.MethodOverride)
|
|
|
|
plug(Plug.Head)
|
2020-01-26 21:36:50 +01:00
|
|
|
plug(Mobilizon.Web.Router)
|
2021-01-25 15:55:52 +01:00
|
|
|
|
|
|
|
@spec websocket_url :: String.t()
|
|
|
|
def websocket_url do
|
|
|
|
String.replace_leading(url(), "http", "ws")
|
|
|
|
end
|
2021-02-04 18:57:26 +01:00
|
|
|
|
2022-09-21 10:15:28 +02:00
|
|
|
if Application.compile_env(:mobilizon, :env) !== :test do
|
2021-02-08 11:52:16 +01:00
|
|
|
plug(Sentry.PlugContext)
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|