Fix CORS / add Access-Control-Allow-Origin * to all methods

The header is not only necessary on the OPTIONS request, but on any method, so I removed the condition.
This commit is contained in:
Otto Richter 2022-04-09 18:59:19 +02:00
parent 1e4dfe2ae8
commit b7cca90972

View file

@ -54,7 +54,6 @@ func Handler(mainDomainSuffix, rawDomain []byte,
} }
// Allow CORS for specified domains // Allow CORS for specified domains
if ctx.IsOptions() {
allowCors := false allowCors := false
for _, allowedCorsDomain := range allowedCorsDomains { for _, allowedCorsDomain := range allowedCorsDomains {
if bytes.Equal(trimmedHost, allowedCorsDomain) { if bytes.Equal(trimmedHost, allowedCorsDomain) {
@ -67,6 +66,7 @@ func Handler(mainDomainSuffix, rawDomain []byte,
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD") ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD")
} }
ctx.Response.Header.Set("Allow", "GET, HEAD, OPTIONS") ctx.Response.Header.Set("Allow", "GET, HEAD, OPTIONS")
if ctx.IsOptions() {
ctx.Response.Header.SetStatusCode(fasthttp.StatusNoContent) ctx.Response.Header.SetStatusCode(fasthttp.StatusNoContent)
return return
} }