From 6fe8375446f9d3470afba4430c9e2f286da69130 Mon Sep 17 00:00:00 2001 From: qwqcode Date: Fri, 14 Oct 2022 16:35:09 +0800 Subject: [PATCH] feat: root path redict to sidebar login page Signed-off-by: qwqcode --- http/a_router.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/http/a_router.go b/http/a_router.go index 10ddaa2..ca5c8b7 100644 --- a/http/a_router.go +++ b/http/a_router.go @@ -21,6 +21,8 @@ func InitRouter(e *echo.Echo) { fileServer := http.FileServer(f) e.Any("/*", echo.WrapHandler(fileServer)) + e.Use(RootPageMiddleware()) + // All Actions action := &action{ db: lib.DB, @@ -94,3 +96,19 @@ func InitRouter(e *echo.Echo) { return c.JSON(200, GetApiVersionDataMap()) }) } + +func RootPageMiddleware() echo.MiddlewareFunc { + return func(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + if c.Request().URL.Path == "/" && c.Request().Method == "GET" { + _, err := pkged.Open("/frontend/sidebar/index.html") + if err == nil { + c.Redirect(http.StatusFound, "./sidebar/") + return nil + } + } + + return next(c) + } + } +}