API: Add OPTIONS wildcard handler to serve CORS preflight requests #5133

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-08-13 15:59:38 +02:00
parent d47b38bc8b
commit a7a41fe000
11 changed files with 239 additions and 28 deletions

View File

@@ -10,21 +10,22 @@ import (
// Echo returns the request and response headers as JSON if debug mode is enabled.
//
// The supported request methods are:
//
// - GET
// - POST
// - PUT
// - PATCH
// - HEAD
// - OPTIONS
// - DELETE
// - CONNECT
// - TRACE
//
// ANY /api/v1/echo
// @Summary returns the request and response headers as JSON if debug mode is enabled
// @Id Echo
// @Success 200
// @Router /api/v1/echo [get]
func Echo(router *gin.RouterGroup) {
router.Any("/echo", func(c *gin.Context) {
methods := []string{
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
http.MethodConnect,
http.MethodTrace,
}
router.Match(methods, "/echo", func(c *gin.Context) {
// Abort if debug mode is disabled.
if !get.Config().Debug() {
AbortFeatureDisabled(c)