filters
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
package middleware
|
||||
|
||||
import "github.com/gofiber/fiber/v3"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// CORSMiddleware creates CORS middleware
|
||||
func CORSMiddleware() fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
c.Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
if strings.Contains(c.Get("Host"), "localhost") {
|
||||
c.Set("Access-Control-Allow-Origin", c.Get("Host"))
|
||||
} else {
|
||||
origins := strings.Join(config.Get().Cors.Origins, ",")
|
||||
c.Set("Access-Control-Allow-Origin", origins)
|
||||
}
|
||||
|
||||
c.Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
c.Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user