fix: use mime.TypeByExtension for static asset Content-Type
CI / test (push) Failing after 12m25s

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.
This commit is contained in:
2026-07-31 15:37:16 -04:00
parent 596f194c3a
commit b18d4bd146
+8 -1
View File
@@ -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()