Add support for CORS

This commit is contained in:
Dan Sosedoff
2017-11-15 15:26:31 -06:00
parent d65f8eb0f5
commit b52394a166
3 changed files with 13 additions and 0 deletions

View File

@@ -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-Allow-Origin", "*")
c.Header("Access-Control-Expose-Headers", "*")
}
}

View File

@@ -10,6 +10,10 @@ func SetupMiddlewares(group *gin.RouterGroup) {
group.Use(requestInspectMiddleware())
}
if command.Opts.CORS {
group.Use(corsMiddleware())
}
group.Use(dbCheckMiddleware())
}