From b18d4bd1461a6f9e2ccb9765867f778893c1dffa Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Fri, 31 Jul 2026 15:37:16 -0400 Subject: [PATCH] fix: use mime.TypeByExtension for static asset Content-Type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http.DetectContentType() cannot detect JS, CSS, SVG, etc. from magic bytes — it falls back to text/plain, causing browsers to reject module scripts with 'Expected a JavaScript module' error. Use mime.TypeByExtension(ext) which correctly maps .js -> application/javascript, .css -> text/css, etc. --- internal/api/router.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/api/router.go b/internal/api/router.go index e2c6c1a..249b0f0 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -1,7 +1,9 @@ package api import ( + "mime" "net/http" + "path" "github.com/gin-gonic/gin" "github.com/llamalink/llamalink/internal/api/handlers" @@ -84,7 +86,12 @@ func New(cfg *config.Config, db *gorm.DB, llamaManager *llama.Manager) *gin.Engi c.String(http.StatusNotFound, "asset not found") return } - c.Data(http.StatusOK, http.DetectContentType(data), data) + ext := path.Ext(filepath) + contentType := mime.TypeByExtension(ext) + if contentType == "" { + contentType = "application/octet-stream" + } + c.Data(http.StatusOK, contentType, data) }) r.GET("/admin", func(c *gin.Context) { index, err := web.Index()