cors management and role showing in public access
This commit is contained in:
parent
103b5b0418
commit
2072d047d4
28
cmd/main.go
28
cmd/main.go
|
|
@ -2,17 +2,39 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
"github.com/pahmiudahgede/senggoldong/config"
|
"github.com/pahmiudahgede/senggoldong/config"
|
||||||
"github.com/pahmiudahgede/senggoldong/router"
|
"github.com/pahmiudahgede/senggoldong/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.SetupConfig()
|
config.SetupConfig()
|
||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
// app.Static(utils.BaseUrl+"/uploads", "./public"+utils.BaseUrl+"/uploads")
|
|
||||||
|
app.Use(cors.New(cors.Config{
|
||||||
|
AllowOrigins: "http://localhost:3000",
|
||||||
|
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
|
||||||
|
AllowHeaders: "Origin, Content-Type, Accept, Authorization, x-api-key",
|
||||||
|
AllowCredentials: true,
|
||||||
|
}))
|
||||||
|
|
||||||
|
app.Use(func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Access-Control-Allow-Origin", "http://localhost:3000")
|
||||||
|
c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
||||||
|
c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key")
|
||||||
|
c.Set("Access-Control-Allow-Credentials", "true")
|
||||||
|
return c.Next()
|
||||||
|
})
|
||||||
|
|
||||||
|
app.Options("*", func(c *fiber.Ctx) error {
|
||||||
|
c.Set("Access-Control-Allow-Origin", "http://localhost:3000")
|
||||||
|
c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
||||||
|
c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key")
|
||||||
|
c.Set("Access-Control-Allow-Credentials", "true")
|
||||||
|
return c.SendStatus(fiber.StatusNoContent)
|
||||||
|
})
|
||||||
|
|
||||||
router.SetupRoutes(app)
|
router.SetupRoutes(app)
|
||||||
config.StartServer(app)
|
|
||||||
|
|
||||||
|
config.StartServer(app)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ import (
|
||||||
"github.com/pahmiudahgede/senggoldong/internal/handler"
|
"github.com/pahmiudahgede/senggoldong/internal/handler"
|
||||||
"github.com/pahmiudahgede/senggoldong/internal/repositories"
|
"github.com/pahmiudahgede/senggoldong/internal/repositories"
|
||||||
"github.com/pahmiudahgede/senggoldong/internal/services"
|
"github.com/pahmiudahgede/senggoldong/internal/services"
|
||||||
"github.com/pahmiudahgede/senggoldong/middleware"
|
|
||||||
"github.com/pahmiudahgede/senggoldong/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RoleRouter(api fiber.Router) {
|
func RoleRouter(api fiber.Router) {
|
||||||
|
|
@ -15,6 +13,6 @@ func RoleRouter(api fiber.Router) {
|
||||||
roleService := services.NewRoleService(roleRepo)
|
roleService := services.NewRoleService(roleRepo)
|
||||||
roleHandler := handler.NewRoleHandler(roleService)
|
roleHandler := handler.NewRoleHandler(roleService)
|
||||||
|
|
||||||
api.Get("/roles", middleware.AuthMiddleware, middleware.RoleMiddleware(utils.RoleAdministrator), roleHandler.GetRoles)
|
api.Get("/roles", roleHandler.GetRoles)
|
||||||
api.Get("/role/:role_id", middleware.AuthMiddleware, middleware.RoleMiddleware(utils.RoleAdministrator), roleHandler.GetRoleByID)
|
api.Get("/role/:role_id", roleHandler.GetRoleByID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue