mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 19:21:46 +03:00
commit
97e31b6c47
@ -76,3 +76,11 @@ func serveResult(result interface{}, err error, c *gin.Context) {
|
||||
|
||||
c.JSON(200, result)
|
||||
}
|
||||
|
||||
func corsMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||
c.Header("Access-Control-Expose-Headers", "*")
|
||||
c.Header("Access-Control-Allow-Origin", command.Opts.CorsOrigin)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
||||
group.Use(requestInspectMiddleware())
|
||||
}
|
||||
|
||||
if command.Opts.Cors {
|
||||
group.Use(corsMiddleware())
|
||||
}
|
||||
|
||||
group.Use(dbCheckMiddleware())
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ type Options struct {
|
||||
ConnectHeaders string `long:"connect-headers" description:"List of headers to pass to the connect backend"`
|
||||
DisableConnectionIdleTimeout bool `long:"no-idle-timeout" description:"Disable connection idle timeout" default:"false"`
|
||||
ConnectionIdleTimeout float64 `long:"idle-timeout" description:"Set connection idle timeout in minutes" default:"180"`
|
||||
Cors bool `long:"cors" description:"Enable Cross-Origin Resource Sharing (CORS)" default:"false"`
|
||||
CorsOrigin string `long:"cors-origin" description:"Allowed CORS origins" default:"*"`
|
||||
}
|
||||
|
||||
var Opts Options
|
||||
|
Loading…
Reference in New Issue
Block a user