mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-05-11 16:44:56 +08:00
38 lines
609 B
Go
38 lines
609 B
Go
//go:build !unembed
|
|
|
|
package middleware
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
"path"
|
|
|
|
"github.com/0xJacky/Nginx-UI/app"
|
|
"github.com/gin-contrib/static"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/uozi-tech/cosy/logger"
|
|
)
|
|
|
|
func mustFs(dir string) static.ServeFileSystem {
|
|
fsys, err := app.GetDistFS()
|
|
if err != nil {
|
|
logger.Error(err)
|
|
return nil
|
|
}
|
|
|
|
distPath := path.Join("dist", dir)
|
|
distFS, err := fs.Sub(fsys, distPath)
|
|
if err != nil {
|
|
logger.Error(err)
|
|
return nil
|
|
}
|
|
|
|
return ServerFileSystemType{
|
|
http.FS(distFS),
|
|
}
|
|
}
|
|
|
|
func ServeStatic() gin.HandlerFunc {
|
|
return static.Serve("/", mustFs(""))
|
|
}
|