mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
API: Add OPTIONS wildcard handler to serve CORS preflight requests #5133
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -24,11 +24,14 @@ var Api = func(conf *config.Config) gin.HandlerFunc {
|
||||
if origin := conf.CORSOrigin(); origin != "" {
|
||||
c.Header(header.AccessControlAllowOrigin, origin)
|
||||
|
||||
// Add additional information to preflight OPTION requests.
|
||||
// Handle OPTIONS preflight requests by adding CORS headers
|
||||
// and aborting the request with HTTP status code 204.
|
||||
if c.Request.Method == http.MethodOptions {
|
||||
c.Header(header.AccessControlAllowHeaders, conf.CORSHeaders())
|
||||
c.Header(header.AccessControlAllowMethods, conf.CORSMethods())
|
||||
c.Header(header.AccessControlMaxAge, header.DefaultAccessControlMaxAge)
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user