package router import ( "context" "github.com/gorilla/handlers" "github.com/gorilla/mux" "net" "net/http" "sonarqube-badge/router/api" "sonarqube-badge/router/views" ) func StartServer(ctx context.Context) { r := mux.NewRouter() // API ROUTES api.ProjectBadgeRouter(r.PathPrefix("/api/project/badge").Subrouter()) api.LoginRouter(r.PathPrefix("/api/login").Subrouter()) // VIEW ROUTES views.IndexRouter(r) views.LoginRouter(r) credentials := handlers.AllowCredentials() methods := handlers.AllowedMethods([]string{"POST", "GET", "OPTIONS"}) ttl := handlers.MaxAge(3600) server := http.Server{ Addr: ":8080", BaseContext: func(listener net.Listener) context.Context { return ctx }, Handler: handlers.CORS(credentials, methods, ttl)(r), } server.ListenAndServe() }