diff --git a/app/app.go b/app/app.go index 62a5897..c4fc411 100644 --- a/app/app.go +++ b/app/app.go @@ -6,6 +6,7 @@ import ( "log" "proxmoxaas-dashboard/app/common" "proxmoxaas-dashboard/app/routes" + "strings" "web" // go will complain here until the first build "github.com/gin-gonic/gin" @@ -49,31 +50,12 @@ func Run() { // setup static resources under web (css, images, modules, scripts) func ServeStatic(router *gin.Engine, m *minify.M) { - css := common.MinifyStatic(m, web.CSS_fs) - router.GET("/css/*css", func(c *gin.Context) { - path, _ := c.Params.Get("css") - data := css[fmt.Sprintf("css%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - images := common.MinifyStatic(m, web.Images_fs) - router.GET("/images/*image", func(c *gin.Context) { - path, _ := c.Params.Get("image") - data := images[fmt.Sprintf("images%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - modules := common.MinifyStatic(m, web.Modules_fs) - router.GET("/modules/*module", func(c *gin.Context) { - path, _ := c.Params.Get("module") - data := modules[fmt.Sprintf("modules%s", path)] - c.Header("Content-Encoding", data.MimeType.Encoding) - c.Data(200, data.MimeType.Type, []byte(data.Data)) - }) - scripts := common.MinifyStatic(m, web.Scripts_fs) - router.GET("/scripts/*script", func(c *gin.Context) { - path, _ := c.Params.Get("script") - data := scripts[fmt.Sprintf("scripts%s", path)] + static := common.MinifyStatic(m, web.Static) + router.GET("/websrc/*path", func(c *gin.Context) { + path, _ := c.Params.Get("path") + trimed_path := strings.Replace(path, "/", "", 1) // replace leading "/" captured by *path + data := static[trimed_path] + fmt.Println(path) c.Header("Content-Encoding", data.MimeType.Encoding) c.Data(200, data.MimeType.Type, []byte(data.Data)) }) diff --git a/web/embed.go b/web/embed.go index dad452b..99be8f9 100644 --- a/web/embed.go +++ b/web/embed.go @@ -5,16 +5,10 @@ import ( ) //go:embed css/* -var CSS_fs embed.FS - //go:embed images/* -var Images_fs embed.FS - //go:embed modules/* -var Modules_fs embed.FS - //go:embed scripts/* -var Scripts_fs embed.FS +var Static embed.FS //go:embed html/* //go:embed templates/* diff --git a/web/html/account.html b/web/html/account.html index d2b2352..30e1139 100644 --- a/web/html/account.html +++ b/web/html/account.html @@ -2,9 +2,9 @@ {{template "head" .}} - - - + + + diff --git a/web/html/config.html b/web/html/config.html index 557fc67..d33caa3 100644 --- a/web/html/config.html +++ b/web/html/config.html @@ -2,11 +2,11 @@ {{template "head" .}} - - - - - + + + + +