Manager: fix mime type for JavaScript files

Go on Windows doesn't know `.js` files should be served with
`application/javascript` mime type, and thus uses the generic `text/plain`
type.
This commit is contained in:
Sybren A. Stüvel 2022-07-13 18:49:35 +02:00
parent 3c290b1f6d
commit cf2d0b553f

View File

@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"mime"
"net/http" "net/http"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -27,6 +28,12 @@ func WebAppHandler() (http.Handler, error) {
// found. // found.
wrappedFS := WrapFS(fs, "index.html") wrappedFS := WrapFS(fs, "index.html")
// Windows doesn't know this mime type. Web browsers won't load the webapp JS
// file when it's served as text/plain.
if err := mime.AddExtensionType(".js", "application/javascript"); err != nil {
return nil, fmt.Errorf("registering mime type for JavaScript files: %w", err)
}
return http.FileServer(http.FS(wrappedFS)), nil return http.FileServer(http.FS(wrappedFS)), nil
} }