mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
feat(backend): Add CORS headers to API responses
This commit is contained in:
9
Gopkg.lock
generated
9
Gopkg.lock
generated
@@ -65,6 +65,14 @@
|
||||
pruneopts = "UT"
|
||||
revision = "563b81fc02b75d664e54da31f787c2cc2186780b"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:2b59aca2665ff804f6606c8829eaee133ddd3aefbc841014660d961b0034f888"
|
||||
name = "github.com/gin-contrib/cors"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "cf4846e6a636a76237a28d9286f163c132e841bc"
|
||||
version = "v1.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:944620dd72b65b9bac1b715134540e5546ffbf84876c3fe065ec594eef640eaf"
|
||||
@@ -385,6 +393,7 @@
|
||||
"github.com/cnf/structhash",
|
||||
"github.com/elazarl/go-bindata-assetfs",
|
||||
"github.com/getsentry/raven-go",
|
||||
"github.com/gin-contrib/cors",
|
||||
"github.com/gin-contrib/gzip",
|
||||
"github.com/gin-contrib/static",
|
||||
"github.com/gin-gonic/contrib/sentry",
|
||||
|
||||
@@ -98,3 +98,7 @@
|
||||
[[constraint]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/gin-contrib/cors"
|
||||
version = "1.2.0"
|
||||
|
||||
9
main.go
9
main.go
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/DeanThompson/ginpprof"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/contrib/sentry"
|
||||
@@ -53,6 +54,14 @@ func setupRouter(router *gin.Engine) {
|
||||
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
router.Use(static.Serve(getViewURL("/static"), newBinaryFileSystem("static")))
|
||||
|
||||
router.Use(cors.New(cors.Config{
|
||||
AllowAllOrigins: true,
|
||||
AllowCredentials: true,
|
||||
AllowMethods: []string{"GET", "POST", "DELETE"},
|
||||
AllowHeaders: []string{"Origin"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
}))
|
||||
|
||||
router.GET(getViewURL("/favicon.ico"), favicon)
|
||||
router.GET(getViewURL("/"), index)
|
||||
router.GET(getViewURL("/help"), help)
|
||||
|
||||
Reference in New Issue
Block a user