0a2ac853e768948143b5bc702434ff3c9410b3a5
[akkoma] / lib / pleroma / web / endpoint.ex
1 defmodule Pleroma.Web.Endpoint do
2 use Phoenix.Endpoint, otp_app: :pleroma
3
4 if Application.get_env(:pleroma, :chat) |> Keyword.get(:enabled) do
5 socket("/socket", Pleroma.Web.UserSocket)
6 end
7
8 socket("/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket)
9
10 # Serve at "/" the static files from "priv/static" directory.
11 #
12 # You should set gzip to true if you are running phoenix.digest
13 # when deploying your static files in production.
14 plug(Plug.Static, at: "/media", from: "uploads", gzip: false)
15
16 plug(
17 Plug.Static,
18 at: "/",
19 from: :pleroma,
20 only: ~w(index.html static finmoji emoji packs sounds images instance sw.js)
21 )
22
23 # Code reloading can be explicitly enabled under the
24 # :code_reloader configuration of your endpoint.
25 if code_reloading? do
26 plug(Phoenix.CodeReloader)
27 end
28
29 plug(TrailingFormatPlug)
30 plug(Plug.RequestId)
31 plug(Plug.Logger)
32
33 plug(
34 Plug.Parsers,
35 parsers: [:urlencoded, :multipart, :json],
36 pass: ["*/*"],
37 json_decoder: Jason
38 )
39
40 plug(Plug.MethodOverride)
41 plug(Plug.Head)
42
43 # The session will be stored in the cookie and signed,
44 # this means its contents can be read but not tampered with.
45 # Set :encryption_salt if you would also like to encrypt it.
46 plug(
47 Plug.Session,
48 store: :cookie,
49 key: "_pleroma_key",
50 signing_salt: "CqaoopA2"
51 )
52
53 plug(Pleroma.Web.Router)
54
55 @doc """
56 Dynamically loads configuration from the system environment
57 on startup.
58
59 It receives the endpoint configuration from the config files
60 and must return the updated configuration.
61 """
62 def load_from_system_env(config) do
63 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
64 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
65 end
66 end