total rebase
[anni] / lib / pleroma / web / endpoint.ex
old mode 100755 (executable)
new mode 100644 (file)
index d8d40cc..2e21049
@@ -9,7 +9,31 @@ defmodule Pleroma.Web.Endpoint do
 
   alias Pleroma.Config
 
-  socket("/socket", Pleroma.Web.UserSocket)
+  socket("/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler,
+    longpoll: false,
+    websocket: [
+      path: "/",
+      compress: false,
+      error_handler: {Pleroma.Web.MastodonAPI.WebsocketHandler, :handle_error, []},
+      fullsweep_after: 20
+    ]
+  )
+
+  socket("/socket", Pleroma.Web.UserSocket,
+    websocket: [
+      path: "/websocket",
+      serializer: [
+        {Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"},
+        {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}
+      ],
+      timeout: 60_000,
+      transport_log: false,
+      compress: false,
+      fullsweep_after: 20
+    ],
+    longpoll: false
+  )
+
   socket("/live", Phoenix.LiveView.Socket)
 
   plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
@@ -19,7 +43,8 @@ defmodule Pleroma.Web.Endpoint do
   plug(Pleroma.Web.Plugs.HTTPSecurityPlug)
   plug(Pleroma.Web.Plugs.UploadedMedia)
 
-  @static_cache_control "public, no-cache"
+  @static_cache_control "public, max-age=1209600"
+  @static_cache_disabled "public, no-cache"
 
   # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files
   # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well
@@ -30,22 +55,32 @@ defmodule Pleroma.Web.Endpoint do
     from: :pleroma,
     only: ["emoji", "images"],
     gzip: true,
-    cache_control_for_etags: "public, max-age=1209600",
+    cache_control_for_etags: @static_cache_control,
     headers: %{
-      "cache-control" => "public, max-age=1209600"
+      "cache-control" => @static_cache_control
     }
   )
 
   plug(Pleroma.Web.Plugs.InstanceStatic,
     at: "/",
     gzip: true,
-    cache_control_for_etags: @static_cache_control,
+    cache_control_for_etags: @static_cache_disabled,
     headers: %{
-      "cache-control" => @static_cache_control
+      "cache-control" => @static_cache_disabled
+    }
+  )
+
+  plug(Pleroma.Web.Plugs.FrontendStatic,
+    at: "/",
+    frontend_type: :primary,
+    only: ["index.html"],
+    gzip: true,
+    cache_control_for_etags: @static_cache_disabled,
+    headers: %{
+      "cache-control" => @static_cache_disabled
     }
   )
 
-  # Careful! No `only` restriction here, as we don't know what frontends contain.
   plug(Pleroma.Web.Plugs.FrontendStatic,
     at: "/",
     frontend_type: :primary,
@@ -62,9 +97,9 @@ defmodule Pleroma.Web.Endpoint do
     at: "/pleroma/admin",
     frontend_type: :admin,
     gzip: true,
-    cache_control_for_etags: @static_cache_control,
+    cache_control_for_etags: @static_cache_disabled,
     headers: %{
-      "cache-control" => @static_cache_control
+      "cache-control" => @static_cache_disabled
     }
   )
 
@@ -79,9 +114,9 @@ defmodule Pleroma.Web.Endpoint do
     only: Pleroma.Constants.static_only_files(),
     # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
     gzip: true,
-    cache_control_for_etags: @static_cache_control,
+    cache_control_for_etags: @static_cache_disabled,
     headers: %{
-      "cache-control" => @static_cache_control
+      "cache-control" => @static_cache_disabled
     }
   )
 
@@ -101,13 +136,10 @@ defmodule Pleroma.Web.Endpoint do
   plug(Plug.Logger, log: :debug)
 
   plug(Plug.Parsers,
-    parsers: [
-      :urlencoded,
-      {:multipart, length: {Config, :get, [[:instance, :upload_limit]]}},
-      :json
-    ],
+    parsers: [:urlencoded, Pleroma.Web.Multipart, :json],
     pass: ["*/*"],
     json_decoder: Jason,
+    # Note: this is compile-time only, won't work for database-config
     length: Config.get([:instance, :upload_limit]),
     body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
   )
@@ -141,47 +173,6 @@ defmodule Pleroma.Web.Endpoint do
 
   plug(Pleroma.Web.Plugs.RemoteIp)
 
-  defmodule Instrumenter do
-    use Prometheus.PhoenixInstrumenter
-  end
-
-  defmodule PipelineInstrumenter do
-    use Prometheus.PlugPipelineInstrumenter
-  end
-
-  defmodule MetricsExporter do
-    use Prometheus.PlugExporter
-  end
-
-  defmodule MetricsExporterCaller do
-    @behaviour Plug
-
-    def init(opts), do: opts
-
-    def call(conn, opts) do
-      prometheus_config = Application.get_env(:prometheus, MetricsExporter, [])
-      ip_whitelist = List.wrap(prometheus_config[:ip_whitelist])
-
-      cond do
-        !prometheus_config[:enabled] ->
-          conn
-
-        ip_whitelist != [] and
-            !Enum.find(ip_whitelist, fn ip ->
-              Pleroma.Helpers.InetHelper.parse_address(ip) == {:ok, conn.remote_ip}
-            end) ->
-          conn
-
-        true ->
-          MetricsExporter.call(conn, opts)
-      end
-    end
-  end
-
-  plug(PipelineInstrumenter)
-
-  plug(MetricsExporterCaller)
-
   plug(Pleroma.Web.Router)
 
   @doc """