1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Add UI and graphs.

Add CORS.
Minor bug fixes.
This commit is contained in:
Ferdinand Mütsch
2019-05-20 20:44:53 +02:00
parent d75da7681b
commit a2095a6f79
3 changed files with 272 additions and 8 deletions

17
main.go
View File

@@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
"github.com/joho/godotenv"
"github.com/rs/cors"
ini "gopkg.in/ini.v1"
"github.com/n1try/wakapi/middlewares"
@@ -85,6 +86,11 @@ func main() {
// Middlewares
authenticate := &middlewares.AuthenticateMiddleware{UserSrvc: userSrvc}
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
Debug: false,
})
// Setup Routing
router := mux.NewRouter()
@@ -98,10 +104,13 @@ func main() {
aggreagations.Methods("GET").HandlerFunc(summaryHandler.Get)
// Sub-Routes Setup
router.PathPrefix("/api").Handler(negroni.Classic().With(
negroni.HandlerFunc(authenticate.Handle),
negroni.Wrap(apiRouter),
))
router.PathPrefix("/api").Handler(negroni.Classic().
With(cors).
With(
negroni.HandlerFunc(authenticate.Handle),
negroni.Wrap(apiRouter),
))
router.PathPrefix("/").Handler(negroni.Classic().With(negroni.Wrap(http.FileServer(http.Dir("./static")))))
// Listen HTTP
portString := "127.0.0.1:" + strconv.Itoa(config.Port)