Allow CORS origins

This commit is contained in:
Martin Pander
2022-11-08 11:01:31 +01:00
parent 8a78711727
commit 82f062b831
7 changed files with 36 additions and 35 deletions

View File

@ -12,6 +12,8 @@ import (
"log"
"net/http"
"github.com/gorilla/handlers"
dashapi "github.com/moustachioed/dash/backend/dashapi"
database "github.com/moustachioed/dash/backend/database"
mapping "github.com/moustachioed/dash/backend/mapping"
@ -29,8 +31,15 @@ func main() {
DefaultApiService := service.NewApiService(db, mapper)
DefaultApiController := dashapi.NewDefaultApiController(DefaultApiService)
cors := handlers.CORS(
// handlers.AllowedMethods([]string{"GET", "POST", "DELETE"}),
handlers.AllowedHeaders([]string{"Accept", "Accept-Language", "Content-Type", "Content-Language", "Origin"}),
handlers.AllowedOrigins([]string{"*"}),
)
router := dashapi.NewRouter(DefaultApiController)
router.Methods("GET", "POST", "DELETE", "OPTIONS")
log.Printf("Starting server.")
log.Fatal(http.ListenAndServe(":8080", router))
log.Fatal(http.ListenAndServe(":8080", cors(router)))
}