1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Endpoint do
6 use Phoenix.Endpoint, otp_app: :pleroma
8 require Pleroma.Constants
10 socket("/socket", Pleroma.Web.UserSocket)
12 plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
14 plug(Pleroma.Web.Plugs.SetLocalePlug)
16 plug(Pleroma.Web.Plugs.HTTPSecurityPlug)
17 plug(Pleroma.Web.Plugs.UploadedMedia)
19 @static_cache_control "public, no-cache"
21 # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
22 # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
23 # Cache-control headers are duplicated in case we turn off etags in the future
24 plug(Pleroma.Web.Plugs.InstanceStatic,
27 cache_control_for_etags: @static_cache_control,
29 "cache-control" => @static_cache_control
33 # Careful! No `only` restriction here, as we don't know what frontends contain.
34 plug(Pleroma.Web.Plugs.FrontendStatic,
36 frontend_type: :primary,
38 cache_control_for_etags: @static_cache_control,
40 "cache-control" => @static_cache_control
44 plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
46 plug(Pleroma.Web.Plugs.FrontendStatic,
48 frontend_type: :admin,
50 cache_control_for_etags: @static_cache_control,
52 "cache-control" => @static_cache_control
56 # Serve at "/" the static files from "priv/static" directory.
58 # You should set gzip to true if you are running phoenix.digest
59 # when deploying your static files in production.
64 only: Pleroma.Constants.static_only_files(),
65 # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
67 cache_control_for_etags: @static_cache_control,
69 "cache-control" => @static_cache_control
74 at: "/pleroma/admin/",
75 from: {:pleroma, "priv/static/adminfe/"}
78 # Code reloading can be explicitly enabled under the
79 # :code_reloader configuration of your endpoint.
81 plug(Phoenix.CodeReloader)
84 plug(Pleroma.Web.Plugs.TrailingFormatPlug)
86 plug(Plug.Logger, log: :debug)
91 {:multipart, length: {Pleroma.Config, :get, [[:instance, :upload_limit]]}},
96 length: Pleroma.Config.get([:instance, :upload_limit]),
97 body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
100 plug(Plug.MethodOverride)
103 secure_cookies = Pleroma.Config.get([__MODULE__, :secure_cookie_flag])
107 do: "__Host-pleroma_key",
111 Pleroma.Config.get([__MODULE__, :extra_cookie_attrs])
114 # The session will be stored in the cookie and signed,
115 # this means its contents can be read but not tampered with.
116 # Set :encryption_salt if you would also like to encrypt it.
121 signing_salt: Pleroma.Config.get([__MODULE__, :signing_salt], "CqaoopA2"),
123 secure: secure_cookies,
127 plug(Pleroma.Web.Plugs.RemoteIp)
129 defmodule Instrumenter do
130 use Prometheus.PhoenixInstrumenter
133 defmodule PipelineInstrumenter do
134 use Prometheus.PlugPipelineInstrumenter
137 defmodule MetricsExporter do
138 use Prometheus.PlugExporter
141 plug(PipelineInstrumenter)
142 plug(MetricsExporter)
144 plug(Pleroma.Web.Router)
147 Dynamically loads configuration from the system environment
150 It receives the endpoint configuration from the config files
151 and must return the updated configuration.
153 def load_from_system_env(config) do
154 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
155 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
159 String.replace_leading(url(), "http", "ws")