Add rules routes

This commit is contained in:
2024-01-24 11:03:08 +01:00
parent 0247413a10
commit 57722116d6
5 changed files with 180 additions and 70 deletions

View File

@ -19,6 +19,7 @@ import (
"git.beisel.it/florian/hostname-service/auth"
"git.beisel.it/florian/hostname-service/docs"
"git.beisel.it/florian/hostname-service/middleware"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
@ -27,7 +28,14 @@ import (
func New() *gin.Engine {
gin.SetMode(gin.DebugMode)
router := gin.Default()
// // Configure CORS
config := cors.DefaultConfig()
config.AllowOrigins = []string{"http://localhost:3000", "http://localhost:8080", "*"} // Set to your frontend's URL
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
config.AllowHeaders = []string{"Origin", "Content-Type", "Authorization"}
router.Use(cors.New(config))
docs.SwaggerInfo.Host = "localhost:8080"
docs.SwaggerInfo.BasePath = "/api/v1"
@ -36,6 +44,7 @@ func New() *gin.Engine {
{
// public routes
v1.POST("/login", auth.LoginHandler)
v1.GET("/login", api.Helloworld)
// Protected Routes
authenticated := v1.Group("/").Use(middleware.Authenticate())
@ -62,7 +71,8 @@ func New() *gin.Engine {
authenticated.GET("/:category", api.ListHostnamesByCategory)
// List available Rules
authenticated.GET("/api/rules", api.ListAvailableRules)
authenticated.GET("/rules", api.ListAvailableRules)
authenticated.GET("/rules/:rule", api.GetRuleStruct)
}
}