middleware.go 467 B

12345678910111213141516171819
  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/recover"
  6. )
  7. func initMiddleware(app *fiber.App, sp ServiceProvider) {
  8. app.Use(cors.New(getCORSConfig(sp)))
  9. app.Use(recover.New())
  10. }
  11. func getCORSConfig(sp ServiceProvider) cors.Config {
  12. return cors.Config{
  13. AllowOrigins: sp.ConfigService().CORSAllowOrigins(),
  14. AllowMethods: sp.ConfigService().CORSAllowMethods(),
  15. }
  16. }