aboutsummaryrefslogtreecommitdiff
path: root/controllers/404.go
blob: 670f2307df0c10fff098773b2700d9f4c4a0fdea (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
package controllers

import (
	"imageboard/utils/shortcuts"
	"strings"

	"github.com/gofiber/fiber/v2"
)

func NotFoundController(ctx *fiber.Ctx) error {
	ctx.Locals("Title", "Page Not Found")

	path := ctx.Path()

	if strings.HasSuffix(path, ".json") {
		return ctx.Status(fiber.StatusNotFound).JSON(fiber.Map{
			"error": "Not Found",
		})
	}

	if len(path) > 1 && strings.Contains(path[1:], ".") && !strings.HasSuffix(path, ".html") {
		return ctx.SendStatus(fiber.StatusNotFound)
	}

	return shortcuts.Render(ctx, "404", nil)
}