logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

endpoint.ex (5273B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Endpoint do
  5. use Phoenix.Endpoint, otp_app: :pleroma
  6. require Pleroma.Constants
  7. alias Pleroma.Config
  8. socket("/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler,
  9. longpoll: false,
  10. websocket: [
  11. path: "/",
  12. compress: false,
  13. connect_info: [:sec_websocket_protocol],
  14. error_handler: {Pleroma.Web.MastodonAPI.WebsocketHandler, :handle_error, []},
  15. fullsweep_after: 20
  16. ]
  17. )
  18. socket("/socket", Pleroma.Web.UserSocket,
  19. websocket: [
  20. path: "/websocket",
  21. serializer: [
  22. {Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"},
  23. {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}
  24. ],
  25. timeout: 60_000,
  26. transport_log: false,
  27. compress: false,
  28. fullsweep_after: 20
  29. ],
  30. longpoll: false
  31. )
  32. socket("/live", Phoenix.LiveView.Socket)
  33. plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
  34. plug(Pleroma.Web.Plugs.LoggerMetadataPath)
  35. plug(Pleroma.Web.Plugs.SetLocalePlug)
  36. plug(CORSPlug)
  37. plug(Pleroma.Web.Plugs.HTTPSecurityPlug)
  38. plug(Pleroma.Web.Plugs.UploadedMedia)
  39. @static_cache_control "public, max-age=1209600"
  40. @static_cache_disabled "public, no-cache"
  41. # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
  42. # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
  43. # Cache-control headers are duplicated in case we turn off etags in the future
  44. plug(
  45. Pleroma.Web.Plugs.InstanceStatic,
  46. at: "/",
  47. from: :pleroma,
  48. only: ["emoji", "images"],
  49. gzip: true,
  50. cache_control_for_etags: @static_cache_control,
  51. headers: %{
  52. "cache-control" => @static_cache_control
  53. }
  54. )
  55. plug(Pleroma.Web.Plugs.InstanceStatic,
  56. at: "/",
  57. gzip: true,
  58. cache_control_for_etags: @static_cache_disabled,
  59. headers: %{
  60. "cache-control" => @static_cache_disabled
  61. }
  62. )
  63. plug(Pleroma.Web.Plugs.FrontendStatic,
  64. at: "/",
  65. frontend_type: :primary,
  66. only: ["index.html"],
  67. gzip: true,
  68. cache_control_for_etags: @static_cache_disabled,
  69. headers: %{
  70. "cache-control" => @static_cache_disabled
  71. }
  72. )
  73. plug(Pleroma.Web.Plugs.FrontendStatic,
  74. at: "/",
  75. frontend_type: :primary,
  76. gzip: true,
  77. cache_control_for_etags: @static_cache_control,
  78. headers: %{
  79. "cache-control" => @static_cache_control
  80. }
  81. )
  82. plug(Plug.Static.IndexHtml, at: "/pleroma/admin/")
  83. plug(Pleroma.Web.Plugs.FrontendStatic,
  84. at: "/pleroma/admin",
  85. frontend_type: :admin,
  86. gzip: true,
  87. cache_control_for_etags: @static_cache_disabled,
  88. headers: %{
  89. "cache-control" => @static_cache_disabled
  90. }
  91. )
  92. # Serve at "/" the static files from "priv/static" directory.
  93. #
  94. # You should set gzip to true if you are running phoenix.digest
  95. # when deploying your static files in production.
  96. plug(
  97. Plug.Static,
  98. at: "/",
  99. from: :pleroma,
  100. only: Pleroma.Constants.static_only_files(),
  101. # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
  102. gzip: true,
  103. cache_control_for_etags: @static_cache_disabled,
  104. headers: %{
  105. "cache-control" => @static_cache_disabled
  106. }
  107. )
  108. plug(Plug.Static,
  109. at: "/pleroma/admin/",
  110. from: {:pleroma, "priv/static/adminfe/"}
  111. )
  112. # Code reloading can be explicitly enabled under the
  113. # :code_reloader configuration of your endpoint.
  114. if code_reloading? do
  115. plug(Phoenix.CodeReloader)
  116. end
  117. plug(Pleroma.Web.Plugs.TrailingFormatPlug)
  118. plug(Plug.RequestId)
  119. plug(Plug.Logger, log: :debug)
  120. plug(Plug.Parsers,
  121. parsers: [:urlencoded, Pleroma.Web.Multipart, :json],
  122. pass: ["*/*"],
  123. json_decoder: Jason,
  124. # Note: this is compile-time only, won't work for database-config
  125. length: Config.get([:instance, :upload_limit]),
  126. body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
  127. )
  128. plug(Plug.MethodOverride)
  129. plug(Plug.Head)
  130. secure_cookies = Config.get([__MODULE__, :secure_cookie_flag])
  131. cookie_name =
  132. if secure_cookies,
  133. do: "__Host-pleroma_key",
  134. else: "pleroma_key"
  135. extra =
  136. Config.get([__MODULE__, :extra_cookie_attrs])
  137. |> Enum.join(";")
  138. # The session will be stored in the cookie and signed,
  139. # this means its contents can be read but not tampered with.
  140. # Set :encryption_salt if you would also like to encrypt it.
  141. plug(
  142. Plug.Session,
  143. store: :cookie,
  144. key: cookie_name,
  145. signing_salt: Config.get([__MODULE__, :signing_salt], "CqaoopA2"),
  146. http_only: true,
  147. secure: secure_cookies,
  148. extra: extra
  149. )
  150. plug(Pleroma.Web.Plugs.RemoteIp)
  151. plug(Pleroma.Web.Router)
  152. @doc """
  153. Dynamically loads configuration from the system environment
  154. on startup.
  155. It receives the endpoint configuration from the config files
  156. and must return the updated configuration.
  157. """
  158. def load_from_system_env(config) do
  159. port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
  160. {:ok, Keyword.put(config, :http, [:inet6, port: port])}
  161. end
  162. def websocket_url do
  163. String.replace_leading(url(), "http", "ws")
  164. end
  165. end