Skip to content

Commit

Permalink
feat | redirects /api/ to / #14
Browse files Browse the repository at this point in the history
First time every in GO. Surprisingly does work.
  • Loading branch information
Lazylllama committed Dec 11, 2024
1 parent 6ad4b11 commit 8cbb530
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func main() {
activityHandler := api.NewActivityApiHandler(userService, activityService)
badgeHandler := api.NewBadgeHandler(userService, summaryService)
captchaHandler := api.NewCaptchaHandler()
redirectHandler := api.NewRedirectApiHandler()

// Compat Handlers
wakatimeV1StatusBarHandler := wtV1Routes.NewStatusBarHandler(userService, summaryService)
Expand Down Expand Up @@ -323,6 +324,7 @@ func main() {
wakatimeV1LeadersHandler.RegisterRoutes(apiRouter)
shieldV1BadgeHandler.RegisterRoutes(apiRouter)
captchaHandler.RegisterRoutes(apiRouter)
redirectHandler.RegisterRoutes(apiRouter)

// Static Routes
// https://github.com/golang/go/issues/43431
Expand Down
22 changes: 22 additions & 0 deletions routes/api/redirect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package api

import (
"net/http"

"github.com/go-chi/chi/v5"
)

type RedirectApiHandler struct{}

func NewRedirectApiHandler() *RedirectApiHandler {
return &RedirectApiHandler{}
}

func (h *RedirectApiHandler) RegisterRoutes(router chi.Router) {
router.Get("/", h.Redirect)
}

// Redirect redirects the user to /
func (h *RedirectApiHandler) Redirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound)
}

0 comments on commit 8cbb530

Please sign in to comment.