aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/controllers/frontend/default_controller.ex
blob: e56288f068e81f39e8d25e74dfff9ff0612cd8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.Frontend.DefaultController do
  defmacro __using__(_opts) do
    quote do
      import Pleroma.Web.FrontendController, only: [index_file_path: 0, index_file_path: 1]

      def index(conn, _params) do
        status = conn.status || 200
        {:ok, index_file_path} = index_file_path(conn.private[:frontend][:config])

        conn
        |> put_resp_content_type("text/html")
        |> send_file(status, index_file_path)
      end

      def api_not_implemented(conn, _params) do
        conn
        |> put_status(404)
        |> json(%{error: "Not implemented"})
      end

      def empty(conn, _params) do
        conn
        |> put_status(204)
        |> text("")
      end

      def fallback(conn, _params) do
        conn
        |> put_status(404)
        |> text("Not found")
      end

      defoverridable index: 2, api_not_implemented: 2, empty: 2, fallback: 2
    end
  end
end