Add request middleware to log incoming form params
This commit is contained in:
parent
639ca96caa
commit
2a4edaf08f
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -76,6 +77,15 @@ func dbCheckMiddleware() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Middleware function to print out request parameters and body for debugging
|
||||||
|
func requestInspectMiddleware() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
err := c.Request.ParseForm()
|
||||||
|
|
||||||
|
log.Println("Request params:", err, c.Request.Form)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func serveStaticAsset(path string, c *gin.Context) {
|
func serveStaticAsset(path string, c *gin.Context) {
|
||||||
data, err := data.Asset("static" + path)
|
data, err := data.Asset("static" + path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,15 +2,24 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/sosedoff/pgweb/pkg/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SetupMiddlewares(group *gin.RouterGroup) {
|
||||||
|
if command.Opts.Debug {
|
||||||
|
group.Use(requestInspectMiddleware())
|
||||||
|
}
|
||||||
|
|
||||||
|
group.Use(dbCheckMiddleware())
|
||||||
|
}
|
||||||
|
|
||||||
func SetupRoutes(router *gin.Engine) {
|
func SetupRoutes(router *gin.Engine) {
|
||||||
router.GET("/", GetHome)
|
router.GET("/", GetHome)
|
||||||
router.GET("/static/*path", GetAsset)
|
router.GET("/static/*path", GetAsset)
|
||||||
|
|
||||||
api := router.Group("/api")
|
api := router.Group("/api")
|
||||||
{
|
{
|
||||||
api.Use(dbCheckMiddleware())
|
SetupMiddlewares(api)
|
||||||
|
|
||||||
api.GET("/info", GetInfo)
|
api.GET("/info", GetInfo)
|
||||||
api.POST("/connect", Connect)
|
api.POST("/connect", Connect)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user