564fc2c1d446a314668d1de3c0f8447f8ca4e2d4
[akkoma] / lib / pleroma / web / endpoint.ex
1 defmodule Pleroma.Web.Endpoint do
2 use Phoenix.Endpoint, otp_app: :pleroma
3
4 socket("/socket", Pleroma.Web.UserSocket)
5
6 # Serve at "/" the static files from "priv/static" directory.
7 #
8 # You should set gzip to true if you are running phoenix.digest
9 # when deploying your static files in production.
10 plug(CORSPlug)
11 plug(Pleroma.Plugs.HTTPSecurityPlug)
12
13 plug(Pleroma.Plugs.UploadedMedia)
14
15 # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
16 # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
17 plug(Pleroma.Plugs.InstanceStatic, at: "/")
18
19 plug(
20 Plug.Static,
21 at: "/",
22 from: :pleroma,
23 only:
24 ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png schemas doc)
25 )
26
27 # Code reloading can be explicitly enabled under the
28 # :code_reloader configuration of your endpoint.
29 if code_reloading? do
30 plug(Phoenix.CodeReloader)
31 end
32
33 plug(TrailingFormatPlug)
34 plug(Plug.RequestId)
35 plug(Plug.Logger)
36
37 plug(
38 Plug.Parsers,
39 parsers: [:urlencoded, :multipart, :json],
40 pass: ["*/*"],
41 json_decoder: Jason,
42 length: Application.get_env(:pleroma, :instance) |> Keyword.get(:upload_limit),
43 body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
44 )
45
46 plug(Plug.MethodOverride)
47 plug(Plug.Head)
48
49 cookie_name =
50 if Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:secure_cookie_flag),
51 do: "__Host-pleroma_key",
52 else: "pleroma_key"
53
54 # The session will be stored in the cookie and signed,
55 # this means its contents can be read but not tampered with.
56 # Set :encryption_salt if you would also like to encrypt it.
57 plug(
58 Plug.Session,
59 store: :cookie,
60 key: cookie_name,
61 signing_salt: {Pleroma.Config, :get, [[__MODULE__, :signing_salt], "CqaoopA2"]},
62 http_only: true,
63 secure:
64 Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:secure_cookie_flag),
65 extra: "SameSite=Strict"
66 )
67
68 plug(Pleroma.Web.Router)
69
70 @doc """
71 Dynamically loads configuration from the system environment
72 on startup.
73
74 It receives the endpoint configuration from the config files
75 and must return the updated configuration.
76 """
77 def load_from_system_env(config) do
78 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
79 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
80 end
81 end