Added CORS-Header in Go #8
1 changed files with 7 additions and 0 deletions
7
main.go
7
main.go
|
@ -16,16 +16,23 @@ import (
|
|||
"git.cliffbreak.de/Cliffbreak/tsviewer/service"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
)
|
||||
|
||||
func Routes(s service.Service, t template.Template) *chi.Mux {
|
||||
router := chi.NewRouter()
|
||||
cors := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
AllowedMethods: []string{"Get"},
|
||||
})
|
||||
router.Use(
|
||||
middleware.Logger,
|
||||
middleware.Timeout(5*time.Second),
|
||||
middleware.DefaultCompress,
|
||||
middleware.RedirectSlashes,
|
||||
middleware.Recoverer,
|
||||
|
||||
cors.Handler,
|
||||
)
|
||||
|
||||
router.Route("/v1", func(r chi.Router) {
|
||||
|
|
Loading…
Reference in a new issue