package serverconfig

import (
	"bitbucket.org/nemt/nemt-portal-api/infra/config"
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
)

func setCORSMiddleware(e *echo.Echo, cfg *config.Config) {
	middlewareConfig := middleware.DefaultCORSConfig

	if !cfg.App.Debug {
		middlewareConfig.AllowOrigins = cfg.HTTP.Auth.FrontendURLs
	}

	e.Pre(middleware.CORSWithConfig(middlewareConfig))
}
