From 19049880136ceb5d2a6951946df50787b74b15d9 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 12 Jul 2025 16:04:49 +0530 Subject: not found controller --- controllers/404.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 controllers/404.go (limited to 'controllers') diff --git a/controllers/404.go b/controllers/404.go new file mode 100644 index 0000000..670f230 --- /dev/null +++ b/controllers/404.go @@ -0,0 +1,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) +} -- cgit v1.2.3