2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.Endpoint do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
2018-10-11 15:37:39 +00:00
|
|
|
Endpoint for Mobilizon app
|
2018-01-14 16:56:50 +00:00
|
|
|
"""
|
2021-06-27 11:15:24 +00:00
|
|
|
alias Mobilizon.Service.ErrorReporting.Sentry, as: SentryAdapter
|
|
|
|
|
|
|
|
if Application.fetch_env!(:mobilizon, :env) !== :test &&
|
|
|
|
SentryAdapter.enabled?() do
|
2021-02-08 10:52:16 +00:00
|
|
|
use Sentry.PlugCapture
|
|
|
|
end
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
use Phoenix.Endpoint, otp_app: :mobilizon
|
2019-12-03 10:29:51 +00:00
|
|
|
use Absinthe.Phoenix.Endpoint
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2021-07-27 17:47:54 +00:00
|
|
|
plug(Mobilizon.Web.Plugs.DetectLocalePlug)
|
2021-02-24 18:06:48 +00:00
|
|
|
|
|
|
|
if Application.fetch_env!(:mobilizon, :env) !== :dev do
|
|
|
|
plug(Mobilizon.Web.Plugs.HTTPSecurityPlug)
|
|
|
|
end
|
2020-09-29 07:53:48 +00:00
|
|
|
|
2019-10-05 17:07:50 +00:00
|
|
|
# For e2e tests
|
2021-09-10 09:34:26 +00: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 17:07:50 +00:00
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
socket("/graphql_socket", Mobilizon.Web.GraphQLSocket,
|
2019-12-03 10:29:51 +00:00
|
|
|
websocket: true,
|
|
|
|
longpoll: false
|
|
|
|
)
|
|
|
|
|
2020-08-27 13:42:09 +00:00
|
|
|
endpoint_config = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)
|
|
|
|
|
|
|
|
if Keyword.get(endpoint_config, :has_reverse_proxy, false) == true do
|
|
|
|
plug(RemoteIp)
|
|
|
|
end
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
plug(Mobilizon.Web.Plugs.UploadedMedia)
|
2019-10-05 17:07:50 +00:00
|
|
|
|
2017-12-08 08:58:14 +00: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.
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Static,
|
|
|
|
at: "/",
|
2020-02-18 07:57:00 +00:00
|
|
|
from: {:mobilizon, "priv/static"},
|
2018-07-27 08:45:35 +00:00
|
|
|
gzip: false,
|
2020-10-30 14:15:07 +00:00
|
|
|
only: ~w(index.html manifest.json service-worker.js css fonts img js favicon.ico robots.txt),
|
2020-02-18 07:57:00 +00:00
|
|
|
only_matching: ["precache-manifest"]
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
# Code reloading can be explicitly enabled under the
|
|
|
|
# :code_reloader configuration of your endpoint.
|
|
|
|
if code_reloading? do
|
2018-07-27 08:45:35 +00:00
|
|
|
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
|
|
|
|
plug(Phoenix.LiveReloader)
|
|
|
|
plug(Phoenix.CodeReloader)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(CORSPlug)
|
|
|
|
plug(Plug.RequestId)
|
|
|
|
plug(Plug.Logger)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2021-04-12 08:13:11 +00:00
|
|
|
upload_limit =
|
|
|
|
Keyword.get(Application.get_env(:mobilizon, :instance, []), :upload_limit, 10_485_760)
|
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Parsers,
|
2021-04-12 08:13:11 +00:00
|
|
|
parsers: [:urlencoded, {:multipart, length: upload_limit}, :json, Absinthe.Plug.Parser],
|
2017-12-08 08:58:14 +00:00
|
|
|
pass: ["*/*"],
|
2019-02-14 13:19:55 +00:00
|
|
|
json_decoder: Jason
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(Plug.MethodOverride)
|
|
|
|
plug(Plug.Head)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
# The session will be stored in the cookie and signed,
|
|
|
|
# this means its contents can be read but not tampered with.
|
|
|
|
# Set :encryption_salt if you would also like to encrypt it.
|
2018-07-27 08:45:35 +00:00
|
|
|
plug(
|
|
|
|
Plug.Session,
|
2017-12-08 08:58:14 +00:00
|
|
|
store: :cookie,
|
2018-10-11 15:37:39 +00:00
|
|
|
key: "_mobilizon_key",
|
2017-12-08 08:58:14 +00:00
|
|
|
signing_salt: "F9CCTF22"
|
2018-07-27 08:45:35 +00:00
|
|
|
)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
plug(Mobilizon.Web.Router)
|
2021-01-25 14:55:52 +00:00
|
|
|
|
|
|
|
@spec websocket_url :: String.t()
|
|
|
|
def websocket_url do
|
|
|
|
String.replace_leading(url(), "http", "ws")
|
|
|
|
end
|
2021-02-04 17:57:26 +00:00
|
|
|
|
2021-06-27 11:15:24 +00:00
|
|
|
if Application.fetch_env!(:mobilizon, :env) !== :test &&
|
|
|
|
SentryAdapter.enabled?() do
|
2021-02-08 10:52:16 +00:00
|
|
|
plug(Sentry.PlugContext)
|
|
|
|
end
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|