1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

explicitly set js mimetype

This commit is contained in:
Harvey Tindall 2021-02-08 15:25:02 +00:00
parent 218882b7c6
commit d061721f56
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 38 additions and 0 deletions

35
embed.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"embed"
"io/fs"
"log"
)
//go:embed data data/html data/web data/web/css data/web/js
var loFS embed.FS
//go:embed lang/common lang/admin lang/email lang/form lang/setup
var laFS embed.FS
var langFS rewriteFS
var localFS rewriteFS
type rewriteFS struct {
fs embed.FS
prefix string
}
func (l rewriteFS) Open(name string) (fs.File, error) { return l.fs.Open(l.prefix + name) }
func (l rewriteFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir(l.prefix + name) }
func (l rewriteFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile(l.prefix + name) }
func FSJoin(elem ...string) string {
out := ""
for _, v := range elem { out += v + "/" }
return out[:len(out)-1]
}
func loadFilesystems() {
langFS = rewriteFS{laFS, "lang/"}
localFS = rewriteFS{loFS, "data/"}
log.Println("Using internal storage")
}

View File

@ -10,6 +10,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"mime"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -569,6 +570,8 @@ func start(asDaemon, firstCall bool) {
} }
cssHeader = app.loadCSSHeader() cssHeader = app.loadCSSHeader()
mime.AddExtensionType(".js", "application/javascript")
app.info.Println("Loading routes") app.info.Println("Loading routes")
if debugMode { if debugMode {
gin.SetMode(gin.DebugMode) gin.SetMode(gin.DebugMode)