Add CORS policy to API

This commit is contained in:
Kevin Kandlbinder 2022-03-02 13:40:18 +01:00
parent ebe9482a27
commit aa55cd834f
3 changed files with 13 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import (
"errors"
chiprometheus "github.com/766b/chi-prometheus"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"net/http"
"strings"
)
@ -13,6 +14,15 @@ import (
func SetupAPI() chi.Router {
router := chi.NewRouter()
router.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"http://*", "https://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: false,
MaxAge: 300,
}))
m := chiprometheus.NewMiddleware("api")
router.Use(m)