5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 02:31:58 +08:00

Added JS case to mimecache

This commit is contained in:
Cody Bentley 2021-09-29 00:50:49 -06:00
parent 9a54f289c4
commit 3de31613a1
2 changed files with 7 additions and 1 deletions

View File

@ -5,8 +5,9 @@ import (
"path/filepath"
"strings"
"sync"
"github.com/gabriel-vasile/mimetype"
)
import "github.com/gabriel-vasile/mimetype"
var (
cache = map[string]string{}
@ -33,6 +34,10 @@ func GetMimetype(filename string, data []byte) string {
result = strings.Replace(result, "text/plain", "text/css", 1)
}
if filepath.Ext(filename) == ".js" && strings.HasPrefix(result, "text/plain") {
result = strings.Replace(result, "text/plain", "text/javascript", 1)
}
if result == "" {
result = "application/octet-stream"
}

View File

@ -14,6 +14,7 @@ func TestGetMimetype(t *testing.T) {
}{
// TODO: Add test cases.
{"css", args{"test.css", []byte("body{margin:0;padding:0;background-color:#d579b2}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;background-color:#ededed}#nav{padding:30px}#nav a{font-weight:700;color:#2c\n3e50}#nav a.router-link-exact-active{color:#42b983}.hello[data-v-4e26ad49]{margin:10px 0}")}, "text/css; charset=utf-8"},
{"js", args{"test.js", []byte("let foo = 'bar'; console.log(foo);")}, "text/javascript; charset=utf-8"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {