added Cors-Header

This commit is contained in:
Niel 2019-02-07 12:13:32 +01:00
parent 1f523a6b7d
commit 53b246a6df

View file

@ -16,16 +16,23 @@ import (
"git.cliffbreak.de/Cliffbreak/tsviewer/service" "git.cliffbreak.de/Cliffbreak/tsviewer/service"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
) )
func Routes(s service.Service, t template.Template) *chi.Mux { func Routes(s service.Service, t template.Template) *chi.Mux {
router := chi.NewRouter() router := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"Get"},
})
router.Use( router.Use(
middleware.Logger, middleware.Logger,
middleware.Timeout(5*time.Second), middleware.Timeout(5*time.Second),
middleware.DefaultCompress, middleware.DefaultCompress,
middleware.RedirectSlashes, middleware.RedirectSlashes,
middleware.Recoverer, middleware.Recoverer,
cors.Handler,
) )
router.Route("/v1", func(r chi.Router) { router.Route("/v1", func(r chi.Router) {