go-jwtserver/internal/router/router.go

32 lines
685 B
Go
Raw Permalink Normal View History

2020-07-16 10:51:50 +02:00
package router
import (
"time"
2020-07-16 14:04:51 +02:00
jwtmiddleware "forge.cadoles.com/mlamalle/go-jwtserver/middleware"
2020-07-16 10:51:50 +02:00
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func InitializeRouter() chi.Router {
r := chi.NewRouter()
// Define base middlewares
r.Use(middleware.RequestID)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.URLFormat)
2020-07-16 14:36:55 +02:00
r.Use(jwtmiddleware.JwtAuthentication)
2020-07-16 10:51:50 +02:00
r.Use(middleware.Timeout(60 * time.Second))
r.Route("/api/", func(r chi.Router) {
// Middleware routes
2020-07-16 14:04:51 +02:00
r.Post("/user/new", jwtmiddleware.CreateAccount)
r.Post("/user/login", jwtmiddleware.Authenticate)
2020-07-21 11:08:01 +02:00
r.Post("/user/refresh", jwtmiddleware.Refresh)
2020-07-16 10:51:50 +02:00
})
return r
}