From 72c73687f03ddabcd7b3697b16db638d2b989dda Mon Sep 17 00:00:00 2001 From: Markson Hon Date: Tue, 5 May 2026 11:20:29 +0800 Subject: [PATCH] fix: prevent panic when _nuxt directory does not exist in embed FS - Wrap /_nuxt/* route registration in fs.Sub() error check - When _nuxt directory is absent (gui build without ngui), skip route registration entirely instead of passing an invalid FS to statigz.FileServer which caused panic on Open('.') --- service/server/router/index.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/service/server/router/index.go b/service/server/router/index.go index aa7a547e..5faeac23 100644 --- a/service/server/router/index.go +++ b/service/server/router/index.go @@ -76,15 +76,16 @@ func ServeGUI(r *gin.Engine) { }) // --- /_nuxt/* route (used by ngui Nuxt 3 build) --- - // When _nuxt/ directory does not exist (legacy gui), statigz safely returns 404 - nuxtFS := webFS.(fs.ReadDirFS) + // Only register the route when _nuxt/ directory exists in the embedded filesystem. + // When it does not exist (e.g. legacy gui build), silently skip to avoid panic + // in statigz.FileServer when the underlying FS does not support Open("."). if sub, subErr := fs.Sub(webFS, "_nuxt"); subErr == nil { - nuxtFS = sub.(fs.ReadDirFS) + nuxtFS := sub.(fs.ReadDirFS) + ns := http.StripPrefix("/_nuxt", statigz.FileServer(nuxtFS)) + r.GET("/_nuxt/*w", func(c *gin.Context) { + ns.ServeHTTP(c.Writer, c.Request) + }) } - ns := http.StripPrefix("/_nuxt", statigz.FileServer(nuxtFS)) - r.GET("/_nuxt/*w", func(c *gin.Context) { - ns.ServeHTTP(c.Writer, c.Request) - }) f, err := webFS.Open("index.html") if err != nil {