ZGGSONG 3 years ago
parent cc1a4d2b5f
commit 9ea273614e

@ -3,7 +3,12 @@ package main
import (
"embed"
"io/fs"
"log"
"net/http"
"os"
"os/exec"
"os/signal"
"strings"
"github.com/gin-gonic/gin"
)
@ -13,12 +18,39 @@ var FS embed.FS
func main() {
go func() {
gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
staticFiles, _ := fs.Sub(FS, "frontend/dist")
router.StaticFS("/static", http.FS(staticFiles))
router.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
if strings.HasPrefix(path, "/static/") {
reader, err := staticFiles.Open("index.html")
if err != nil {
log.Fatal(err)
}
defer reader.Close()
stat, err := reader.Stat()
if err != nil {
log.Fatal(err)
}
c.DataFromReader(http.StatusOK, stat.Size(), "text/html", reader, nil)
} else {
c.Status(http.StatusNotFound)
}
})
router.Run(":27149")
}()
chromePath := "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
cmd := exec.Command(chromePath, "--app=http://127.0.0.1:27149/static/index.html")
cmd.Start()
chSingal := make(chan os.Signal, 1)
signal.Notify(chSingal, os.Interrupt)
select {
case <-chSingal:
cmd.Process.Kill()
}
}

Loading…
Cancel
Save