Added CORS middleware

This commit is contained in:
Deluan 2020-01-09 13:51:54 -05:00 committed by Deluan Quintão
parent ff5b91da54
commit 85f7fdd285
4 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,7 @@ setup: jamstash
.PHONY: run
run:
@reflex -s -r "(\.go$$|sonic.toml)" -R "Jamstash-master" -- go run .
@reflex -s -d none -r "(\.go$$|sonic.toml)" -R "Jamstash-master" -- go run .
.PHONY: test
test:

2
app.go
View File

@ -12,6 +12,7 @@ import (
"github.com/cloudsonic/sonic-server/scanner"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
)
type App struct {
@ -40,6 +41,7 @@ func (a *App) Run(addr string) {
func (a *App) initRoutes() {
r := chi.NewRouter()
r.Use(cors.Default().Handler)
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Recoverer)

1
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/fatih/camelcase v0.0.0-20160318181535-f6a740d52f96 // indirect
github.com/fatih/structs v1.0.0 // indirect
github.com/go-chi/chi v4.0.2+incompatible
github.com/go-chi/cors v1.0.0
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
github.com/google/wire v0.4.0
github.com/kennygrant/sanitize v0.0.0-20170120101633-6a0bfdde8629

2
go.sum
View File

@ -24,6 +24,8 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/cors v1.0.0 h1:e6x8k7uWbUwYs+aXDoiUzeQFT6l0cygBYyNhD7/1Tg0=
github.com/go-chi/cors v1.0.0/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk=