middleware.go 541 B

1234567891011121314151617181920212223
  1. package fiber
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "github.com/gofiber/fiber/v2/middleware/cors"
  5. "github.com/gofiber/fiber/v2/middleware/healthcheck"
  6. "github.com/gofiber/fiber/v2/middleware/recover"
  7. )
  8. func initMiddleware(app *fiber.App, sp ServiceProvider) {
  9. app.Use(
  10. cors.New(getCORSConfig(sp)),
  11. recover.New(),
  12. healthcheck.New(),
  13. )
  14. }
  15. func getCORSConfig(sp ServiceProvider) cors.Config {
  16. return cors.Config{
  17. AllowOrigins: sp.ConfigService().CORSAllowOrigins(),
  18. AllowMethods: sp.ConfigService().CORSAllowMethods(),
  19. }
  20. }