package main import ( "bufio" "log" "os/exec" "strings" "git.phc.dm.unipi.it/phc/storage/database" "git.phc.dm.unipi.it/phc/storage/routes" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/fiber/v2/middleware/recover" ) func main() { router := &routes.Router{ Database: database.NewJSON("database.local.json"), } app := fiber.New() app.Use(logger.New()) app.Use(recover.New()) // Static files app.Static("/", "/_frontend/dist") app.Route("/api", router.Api) if strings.HasPrefix(Config.Mode, "dev") { log.Printf(`Running dev server for frontend: "npm run dev"`) cmd := exec.Command("sh", "-c", "cd _frontend/ && npm run dev") cmdStdout, _ := cmd.StdoutPipe() go func() { s := bufio.NewScanner(cmdStdout) for s.Scan() { log.Printf("[ViteJS] %s", s.Text()) } if err := s.Err(); err != nil { log.Fatal(err) } }() err := cmd.Start() if err != nil { log.Fatal(err) } } log.Fatal(app.Listen(Config.Host)) }