refactor default allow origins
this should be less error prone
This commit is contained in:
parent
765770efdb
commit
1fabba474b
|
@ -499,23 +499,25 @@ func CopyModelHandler(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Serve(ln net.Listener, origins []string) error {
|
var defaultAllowOrigins = []string{
|
||||||
|
"localhost",
|
||||||
|
"127.0.0.1",
|
||||||
|
"0.0.0.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
func Serve(ln net.Listener, allowOrigins []string) error {
|
||||||
config := cors.DefaultConfig()
|
config := cors.DefaultConfig()
|
||||||
config.AllowWildcard = true
|
config.AllowWildcard = true
|
||||||
config.AllowOrigins = append(origins, []string{
|
|
||||||
"http://localhost",
|
config.AllowOrigins = allowOrigins
|
||||||
"http://localhost:*",
|
for _, allowOrigin := range defaultAllowOrigins {
|
||||||
"https://localhost",
|
config.AllowOrigins = append(config.AllowOrigins,
|
||||||
"https://localhost:*",
|
fmt.Sprintf("http://%s", allowOrigin),
|
||||||
"http://127.0.0.1",
|
fmt.Sprintf("https://%s", allowOrigin),
|
||||||
"http://127.0.0.1:*",
|
fmt.Sprintf("http://%s:*", allowOrigin),
|
||||||
"https://127.0.0.1",
|
fmt.Sprintf("https://%s:*", allowOrigin),
|
||||||
"https://127.0.0.1:*",
|
)
|
||||||
"http://0.0.0.0",
|
}
|
||||||
"http://0.0.0.0:*",
|
|
||||||
"https://0.0.0.0",
|
|
||||||
"https://0.0.0.0:*",
|
|
||||||
}...)
|
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(cors.New(config))
|
r.Use(cors.New(config))
|
||||||
|
|
Loading…
Reference in a new issue