feat(backend): Add CORS headers to API responses

This commit is contained in:
Łukasz Mierzwa
2018-06-12 13:58:43 +02:00
parent 24cac4bfd8
commit 5de0efd7b4
3 changed files with 22 additions and 0 deletions

9
Gopkg.lock generated
View File

@@ -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",

View File

@@ -98,3 +98,7 @@
[[constraint]]
branch = "v2"
name = "gopkg.in/yaml.v2"
[[constraint]]
name = "github.com/gin-contrib/cors"
version = "1.2.0"

View File

@@ -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)