diff --git a/main.go b/main.go index bd42626..b9c6a6f 100644 --- a/main.go +++ b/main.go @@ -5,10 +5,12 @@ package main import ( + "bytes" "context" "errors" "flag" "fmt" + "io" "io/fs" "log" "net" @@ -113,8 +115,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) { if s.DefaultLanguage != domain.LanguageUnd { supported = append( - []language.Tag{language.Make(s.DefaultLanguage.Code())}, - supported..., + []language.Tag{language.Make(s.DefaultLanguage.Code())}, supported..., ) } @@ -163,7 +164,24 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) { return } - http.ServeContent(w, r, res.Name(), domain.ResourceModTime(res), res) + // TODO(toby3d) : ugly workaround, must be refactored + resFile, err := contentDir.Open(res.File.Path()) + if err != nil { + http.Error(w, "cannot open: "+err.Error(), http.StatusInternalServerError) + + return + } + defer resFile.Close() + + resBytes, err := io.ReadAll(resFile) + if err != nil { + http.Error(w, "cannot read all: "+err.Error(), http.StatusInternalServerError) + + return + } + defer resFile.Close() + + http.ServeContent(w, r, res.Name(), domain.ResourceModTime(res), bytes.NewReader(resBytes)) return }