mount static files to routes

This commit is contained in:
c9s 2021-01-29 11:19:37 +08:00
parent e1926523e3
commit 8031c6066e

View File

@ -8,6 +8,7 @@ import (
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/markbates/pkger"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/service" "github.com/c9s/bbgo/pkg/service"
@ -205,5 +206,10 @@ func RunServer(ctx context.Context, userConfig *Config, environ *Environment) er
c.JSON(200, gin.H{"message": "pong"}) c.JSON(200, gin.H{"message": "pong"})
}) })
fs := pkger.Dir("/frontend/out")
r.NoRoute(func(c *gin.Context) {
http.FileServer(fs).ServeHTTP(c.Writer, c.Request)
})
return r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") return r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
} }