mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Config: Update CORS header defaults and add /api/v1/echo endpoint #3931
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
49
internal/api/echo.go
Normal file
49
internal/api/echo.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/get"
|
||||
)
|
||||
|
||||
// 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
|
||||
func Echo(router *gin.RouterGroup) {
|
||||
router.Any("/echo", func(c *gin.Context) {
|
||||
// Abort if debug mode is disabled.
|
||||
if !get.Config().Debug() {
|
||||
AbortFeatureDisabled(c)
|
||||
return
|
||||
} else if c.Request == nil || c.Writer == nil {
|
||||
AbortUnexpectedError(c)
|
||||
return
|
||||
}
|
||||
|
||||
// Return request information.
|
||||
echoResponse := gin.H{
|
||||
"url": c.Request.URL.String(),
|
||||
"method": c.Request.Method,
|
||||
"headers": map[string]http.Header{
|
||||
"request": c.Request.Header,
|
||||
"response": c.Writer.Header(),
|
||||
},
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, echoResponse)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user