forked from phc/cluster-dashboard
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/config"
|
|
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/database"
|
|
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/executor"
|
|
"git.phc.dm.unipi.it/phc/cluster-dashboard/backend/routes"
|
|
)
|
|
|
|
func main() {
|
|
ex := &executor.Mock{} // to try out locally this project in a reasonable way
|
|
db := database.NewSimpleDatabase(ex)
|
|
|
|
router := &routes.Service{
|
|
Database: db,
|
|
}
|
|
|
|
app := fiber.New()
|
|
|
|
app.Route("/", router.Root)
|
|
app.Route("/api", router.Api)
|
|
|
|
if strings.HasPrefix(config.Mode, "dev") {
|
|
setupDevServer()
|
|
}
|
|
|
|
log.Fatal(app.Listen(config.Host))
|
|
}
|
|
|
|
func setupDevServer() {
|
|
log.Printf(`Running dev server for frontend: "npm run dev"`)
|
|
cmd := exec.Command("sh", "-c", "npm run dev")
|
|
cmdStdout, _ := cmd.StdoutPipe()
|
|
cmdStderr, _ := cmd.StderrPipe()
|
|
|
|
viteLogger := log.New(os.Stderr, color.HiGreenString("[ViteJS]")+" ", log.Ltime|log.Lmsgprefix)
|
|
|
|
go func() {
|
|
s := bufio.NewScanner(io.MultiReader(cmdStdout, cmdStderr))
|
|
for s.Scan() {
|
|
viteLogger.Print(s.Text())
|
|
}
|
|
if err := s.Err(); err != nil {
|
|
viteLogger.Fatal(err)
|
|
}
|
|
}()
|
|
|
|
err := cmd.Start()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|