update copyright years to 2019
[akkoma] / lib / pleroma / web / endpoint.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Endpoint do
6 use Phoenix.Endpoint, otp_app: :pleroma
7
8 socket("/socket", Pleroma.Web.UserSocket)
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(CORSPlug)
15 plug(Pleroma.Plugs.HTTPSecurityPlug)
16
17 plug(Pleroma.Plugs.UploadedMedia)
18
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 plug(Pleroma.Plugs.InstanceStatic, at: "/")
22
23 plug(
24 Plug.Static,
25 at: "/",
26 from: :pleroma,
27 only:
28 ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png schemas doc)
29 )
30
31 # Code reloading can be explicitly enabled under the
32 # :code_reloader configuration of your endpoint.
33 if code_reloading? do
34 plug(Phoenix.CodeReloader)
35 end
36
37 plug(TrailingFormatPlug)
38 plug(Plug.RequestId)
39 plug(Plug.Logger)
40
41 plug(
42 Plug.Parsers,
43 parsers: [:urlencoded, :multipart, :json],
44 pass: ["*/*"],
45 json_decoder: Jason,
46 length: Application.get_env(:pleroma, :instance) |> Keyword.get(:upload_limit),
47 body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
48 )
49
50 plug(Plug.MethodOverride)
51 plug(Plug.Head)
52
53 cookie_name =
54 if Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:secure_cookie_flag),
55 do: "__Host-pleroma_key",
56 else: "pleroma_key"
57
58 # The session will be stored in the cookie and signed,
59 # this means its contents can be read but not tampered with.
60 # Set :encryption_salt if you would also like to encrypt it.
61 plug(
62 Plug.Session,
63 store: :cookie,
64 key: cookie_name,
65 signing_salt: {Pleroma.Config, :get, [[__MODULE__, :signing_salt], "CqaoopA2"]},
66 http_only: true,
67 secure:
68 Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.get(:secure_cookie_flag),
69 extra: "SameSite=Strict"
70 )
71
72 plug(Pleroma.Web.Router)
73
74 @doc """
75 Dynamically loads configuration from the system environment
76 on startup.
77
78 It receives the endpoint configuration from the config files
79 and must return the updated configuration.
80 """
81 def load_from_system_env(config) do
82 port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
83 {:ok, Keyword.put(config, :http, [:inet6, port: port])}
84 end
85 end