2025-02-22 16:15:38 +08:00

32 lines
662 B
Go

package internalhttp
import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"go.uber.org/fx"
chimware "github.com/go-chi/chi/v5/middleware"
)
var Module = fx.Module("router",
fx.Provide(initRouter),
)
func initRouter() chi.Router {
router := chi.NewRouter()
localCors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
AllowedHeaders: []string{"Accept", "Content-Type", "Authorization", "X-Device", "X-Client-Ip"},
AllowCredentials: true,
Debug: true,
})
router.Use(
localCors.Handler,
chimware.RequestID,
)
return router
}