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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user