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(Pleroma.Plugs.SetLocalePlug)
14 plug(Pleroma.Plugs.HTTPSecurityPlug)
15 plug(Pleroma.Plugs.UploadedMedia)
17 @static_cache_control "public, no-cache"
19 # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
20 # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
21 # Cache-control headers are duplicated in case we turn off etags in the future
22 plug(Pleroma.Plugs.InstanceStatic,
25 cache_control_for_etags: @static_cache_control,
27 "cache-control" => @static_cache_control
31 # Serve at "/" the static files from "priv/static" directory.
33 # You should set gzip to true if you are running phoenix.digest
34 # when deploying your static files in production.
39 only: Pleroma.Constants.static_only_files(),
40 # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
42 cache_control_for_etags: @static_cache_control,
44 "cache-control" => @static_cache_control
48 plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
51 at: "/pleroma/admin/",
52 from: {:pleroma, "priv/static/adminfe/"}
55 # Code reloading can be explicitly enabled under the
56 # :code_reloader configuration of your endpoint.
58 plug(Phoenix.CodeReloader)
61 plug(Pleroma.Plugs.TrailingFormatPlug)
63 plug(Plug.Logger, log: :debug)
68 {:multipart, length: {Pleroma.Config, :get, [[:instance, :upload_limit]]}},
73 length: Pleroma.Config.get([:instance, :upload_limit]),
74 body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
77 plug(Plug.MethodOverride)
80 secure_cookies = Pleroma.Config.get([__MODULE__, :secure_cookie_flag])
84 do: "__Host-pleroma_key",
88 Pleroma.Config.get([__MODULE__, :extra_cookie_attrs])
91 # The session will be stored in the cookie and signed,
92 # this means its contents can be read but not tampered with.
93 # Set :encryption_salt if you would also like to encrypt it.
98 signing_salt: Pleroma.Config.get([__MODULE__, :signing_salt], "CqaoopA2"),
100 secure: secure_cookies,
104 plug(Pleroma.Plugs.RemoteIp)
106 defmodule Instrumenter do
107 use Prometheus.PhoenixInstrumenter
110 defmodule PipelineInstrumenter do
111 use Prometheus.PlugPipelineInstrumenter
114 defmodule MetricsExporter do
115 use Prometheus.PlugExporter
118 plug(PipelineInstrumenter)
119 plug(MetricsExporter)
121 plug(Pleroma.Web.Router)
124 Dynamically loads configuration from the system environment
127 It receives the endpoint configuration from the config files
128 and must return the updated configuration.
130 def load_from_system_env(config) do
131 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
132 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
136 String.replace_leading(url(), "http", "ws")