From 2e3182491058016ddd132690d340a5720ff1db0d Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Wed, 6 Nov 2024 21:34:05 +0700 Subject: [PATCH] fix!: Redirect old `/remote-nodes/logs` to `/remote-nodes/id/{id}` #155 The old `/remote-nodes/logs/?node_id={id}` is not being used anymore and should be redirected to the new path: `/remote-nodes/id/{id}`. Remove the route once search engines result shows the new path --- internal/handler/response.go | 13 +++++++++++++ internal/handler/routes.go | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/internal/handler/response.go b/internal/handler/response.go index bf375cc..4f31f9b 100644 --- a/internal/handler/response.go +++ b/internal/handler/response.go @@ -13,6 +13,19 @@ import ( "github.com/gofiber/fiber/v2/middleware/adaptor" ) +// Redirect old `/remote-nodes/logs/?node_id={id}` path to `/remote-nodes/id/{id}` +// +// This is temporary handler to redirect old path to new one. Once search +// engine results updated to the new path, this handler should be removed. +func (s *fiberServer) redirectLogs(c *fiber.Ctx) error { + id := c.QueryInt("node_id", 0) + if id == 0 { + return c.Redirect("/remote-nodes", fiber.StatusMovedPermanently) + } + + return c.Redirect(fmt.Sprintf("/remote-nodes/id/%d", id), fiber.StatusMovedPermanently) +} + // Render Home Page func (s *fiberServer) homeHandler(c *fiber.Ctx) error { p := views.Meta{ diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 5038b09..12cf8db 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -7,6 +7,10 @@ func (s *fiberServer) Routes() { s.App.Get("/add-node", s.addNodeHandler) s.App.Put("/add-node", s.addNodeHandler) + // This is temporary route to redirect old path to new one. Once search + // engine results updated to the new path, this route should be removed. + s.App.Get("/remote-nodes/logs", s.redirectLogs) + // V1 API routes v1 := s.App.Group("/api/v1")