X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fwebserver%2Fserver.go;h=8fd7e44024c247aa2ee29ccaa73ee29141ff5f8b;hb=356af1eaeae9bb7d38b84d87134b1afe7a496e85;hp=40ce9486baa9772480aa5a564b3a7210501718b3;hpb=40a7183f3b4aa32379aa8b4949f5f9c5e32f79f6;p=src%2Fxds%2Fxds-server.git diff --git a/lib/webserver/server.go b/lib/webserver/server.go index 40ce948..8fd7e44 100644 --- a/lib/webserver/server.go +++ b/lib/webserver/server.go @@ -1,6 +1,7 @@ package webserver import ( + "fmt" "net/http" "os" @@ -83,7 +84,7 @@ func (s *Server) Serve() error { s.sessions = session.NewClientSessions(s.router, s.log, cookieMaxAge) // Create REST API - s.api = apiv1.New(s.sessions, s.cfg, s.mfolder, s.router) + s.api = apiv1.New(s.router, s.sessions, s.cfg, s.mfolder, s.sdks) // Websocket routes s.sIOServer, err = socketio.NewServer(nil) @@ -99,12 +100,12 @@ func (s *Server) Serve() error { */ // Web Application (serve on / ) - idxFile := path.Join(s.cfg.WebAppDir, indexFilename) + idxFile := path.Join(s.cfg.FileConf.WebAppDir, indexFilename) if _, err := os.Stat(idxFile); err != nil { s.log.Fatalln("Web app directory not found, check/use webAppDir setting in config file: ", idxFile) } - s.log.Infof("Serve WEB app dir: %s", s.cfg.WebAppDir) - s.router.Use(static.Serve("/", static.LocalFile(s.cfg.WebAppDir, true))) + s.log.Infof("Serve WEB app dir: %s", s.cfg.FileConf.WebAppDir) + s.router.Use(static.Serve("/", static.LocalFile(s.cfg.FileConf.WebAppDir, true))) s.webApp = s.router.Group("/", s.serveIndexFile) { s.webApp.GET("/") @@ -113,7 +114,8 @@ func (s *Server) Serve() error { // Serve in the background serveError := make(chan error, 1) go func() { - serveError <- http.ListenAndServe(":"+s.cfg.HTTPPort, s.router) + fmt.Printf("Web Server running on localhost:%s ...\n", s.cfg.FileConf.HTTPPort) + serveError <- http.ListenAndServe(":"+s.cfg.FileConf.HTTPPort, s.router) }() // Wait for stop, restart or error signals @@ -152,12 +154,10 @@ func (s *Server) middlewareXDSDetails() gin.HandlerFunc { // CORS middleware func (s *Server) middlewareCORS() gin.HandlerFunc { return func(c *gin.Context) { - if c.Request.Method == "OPTIONS" { c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Headers", "Content-Type") - c.Header("Access-Control-Allow-Methods", "POST, DELETE, GET, PUT") - c.Header("Content-Type", "application/json") + c.Header("Access-Control-Allow-Methods", "GET, POST, DELETE") c.Header("Access-Control-Max-Age", cookieMaxAge) c.AbortWithStatus(204) return