mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
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:
parent
1e4dfe2ae8
commit
b7cca90972
1 changed files with 12 additions and 12 deletions
|
@ -54,19 +54,19 @@ func Handler(mainDomainSuffix, rawDomain []byte,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow CORS for specified domains
|
// Allow CORS for specified domains
|
||||||
|
allowCors := false
|
||||||
|
for _, allowedCorsDomain := range allowedCorsDomains {
|
||||||
|
if bytes.Equal(trimmedHost, allowedCorsDomain) {
|
||||||
|
allowCors = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if allowCors {
|
||||||
|
ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD")
|
||||||
|
}
|
||||||
|
ctx.Response.Header.Set("Allow", "GET, HEAD, OPTIONS")
|
||||||
if ctx.IsOptions() {
|
if ctx.IsOptions() {
|
||||||
allowCors := false
|
|
||||||
for _, allowedCorsDomain := range allowedCorsDomains {
|
|
||||||
if bytes.Equal(trimmedHost, allowedCorsDomain) {
|
|
||||||
allowCors = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if allowCors {
|
|
||||||
ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
|
|
||||||
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD")
|
|
||||||
}
|
|
||||||
ctx.Response.Header.Set("Allow", "GET, HEAD, OPTIONS")
|
|
||||||
ctx.Response.Header.SetStatusCode(fasthttp.StatusNoContent)
|
ctx.Response.Header.SetStatusCode(fasthttp.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue