endpoint.ex 1.84 KB
Newer Older
lain's avatar
lain committed
1
2
3
defmodule Pleroma.Web.Endpoint do
  use Phoenix.Endpoint, otp_app: :pleroma

4
  if Application.get_env(:pleroma, :chat) |> Keyword.get(:enabled) do
lain's avatar
lain committed
5
    socket("/socket", Pleroma.Web.UserSocket)
6
  end
lain's avatar
lain committed
7
8

  socket("/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket)
lain's avatar
lain committed
9
10
11
12
13

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phoenix.digest
  # when deploying your static files in production.
14
  plug(Plug.Static, at: "/media", from: Pleroma.Upload.upload_path(), gzip: false)
lain's avatar
lain committed
15
16
17
18
19

  plug(
    Plug.Static,
    at: "/",
    from: :pleroma,
Hakaba Hitoyo's avatar
Hakaba Hitoyo committed
20
    only: ~w(index.html static finmoji emoji packs sounds images instance sw.js)
lain's avatar
lain committed
21
  )
lain's avatar
lain committed
22
23
24
25

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
lain's avatar
lain committed
26
    plug(Phoenix.CodeReloader)
lain's avatar
lain committed
27
28
  end

lain's avatar
lain committed
29
30
31
  plug(TrailingFormatPlug)
  plug(Plug.RequestId)
  plug(Plug.Logger)
lain's avatar
lain committed
32

lain's avatar
lain committed
33
34
  plug(
    Plug.Parsers,
lain's avatar
lain committed
35
36
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
37
38
    json_decoder: Jason,
    length: Application.get_env(:pleroma, :instance) |> Keyword.get(:upload_limit)
lain's avatar
lain committed
39
  )
lain's avatar
lain committed
40

lain's avatar
lain committed
41
42
  plug(Plug.MethodOverride)
  plug(Plug.Head)
lain's avatar
lain committed
43
44
45
46

  # The session will be stored in the cookie and signed,
  # this means its contents can be read but not tampered with.
  # Set :encryption_salt if you would also like to encrypt it.
lain's avatar
lain committed
47
48
  plug(
    Plug.Session,
lain's avatar
lain committed
49
50
51
    store: :cookie,
    key: "_pleroma_key",
    signing_salt: "CqaoopA2"
lain's avatar
lain committed
52
  )
lain's avatar
lain committed
53

lain's avatar
lain committed
54
  plug(Pleroma.Web.Router)
lain's avatar
lain committed
55
56
57
58
59
60
61
62
63
64
65
66
67

  @doc """
  Dynamically loads configuration from the system environment
  on startup.

  It receives the endpoint configuration from the config files
  and must return the updated configuration.
  """
  def load_from_system_env(config) do
    port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
    {:ok, Keyword.put(config, :http, [:inet6, port: port])}
  end
end