-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcors.go
30 lines (26 loc) · 793 Bytes
/
cors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package webutils
import (
"os"
"strings"
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// ConfigureCORSMiddleware returns an echo.MiddlewareFunc with the whitelisted corsDomains origins
func ConfigureCORSMiddleware(corsDomains []string) echo.MiddlewareFunc {
// CORS_DOMAINS env var can be one url or a comma-delinated list of urls, ie:
// http://localhost:8004,https://website.com
if corsDomains == nil {
corsDomains = strings.Split(os.Getenv("CORS_DOMAINS"), ",")
}
return middleware.CORSWithConfig(middleware.CORSConfig{
AllowCredentials: true,
AllowOrigins: corsDomains,
// which we can explode
AllowHeaders: []string{
echo.HeaderOrigin,
echo.HeaderContentType,
echo.HeaderAccept,
echo.HeaderAuthorization,
},
})
}