Merge branch 'favicon_tag' into 'develop'
[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: Pleroma.Upload.upload_path(), 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 favicon.png)
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 length: Application.get_env(:pleroma, :instance) |> Keyword.get(:upload_limit)
39 )
40
41 plug(Plug.MethodOverride)
42 plug(Plug.Head)
43
44 # The session will be stored in the cookie and signed,
45 # this means its contents can be read but not tampered with.
46 # Set :encryption_salt if you would also like to encrypt it.
47 plug(
48 Plug.Session,
49 store: :cookie,
50 key: "_pleroma_key",
51 signing_salt: "CqaoopA2"
52 )
53
54 plug(Pleroma.Web.Router)
55
56 @doc """
57 Dynamically loads configuration from the system environment
58 on startup.
59
60 It receives the endpoint configuration from the config files
61 and must return the updated configuration.
62 """
63 def load_from_system_env(config) do
64 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
65 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
66 end
67 end