Files
scrutiny/webapp/backend/pkg/web/server.go
T
Jason Kulatunga 2ad120c87b added debug logging message for detected devices.
adding a mocked class for Config.
Adding device type to Device struct. Will eventually be needed for raid drives.
adding End-to-end testing capabilties.
Added testdata json files for webserver requests.
Seperated Start code and Setup code in webapp so we can test.
renamed "smart_attributes" to "ata_attributes" - Backwards incomatible change.
Added front end device sorting (red, yellow, green)
show unknown icon/status if drive has no smart data yet.
Moved all attribute "getters" into the controller.
created a device-sort pipe.
2020-08-26 21:35:13 -07:00

57 lines
1.4 KiB
Go

package web
import (
"fmt"
"github.com/analogj/scrutiny/webapp/backend/pkg/config"
"github.com/analogj/scrutiny/webapp/backend/pkg/database"
"github.com/analogj/scrutiny/webapp/backend/pkg/web/handler"
"github.com/gin-gonic/gin"
"net/http"
)
type AppEngine struct {
Config config.Interface
}
func (ae *AppEngine) Setup() *gin.Engine {
r := gin.Default()
r.Use(database.DatabaseHandler(ae.Config.GetString("web.database.location")))
api := r.Group("/api")
{
api.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
})
})
api.POST("/devices/register", handler.RegisterDevices)
api.GET("/summary", handler.GetDevicesSummary)
api.POST("/device/:wwn/smart", handler.UploadDeviceMetrics)
api.POST("/device/:wwn/selftest", handler.UploadDeviceSelfTests)
api.GET("/device/:wwn/details", handler.GetDeviceDetails)
}
//Static request routing
r.StaticFS("/web", http.Dir(ae.Config.GetString("web.src.frontend.path")))
//redirect base url to /web
r.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusFound, "/web")
})
//catch-all, serve index page.
r.NoRoute(func(c *gin.Context) {
c.File(fmt.Sprintf("%s/index.html", ae.Config.GetString("web.src.frontend.path")))
})
return r
}
func (ae *AppEngine) Start() error {
r := ae.Setup()
return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port")))
}