🚧 Serve Page Resource bytes
This commit is contained in:
parent
5c75e6f9e9
commit
860d56cfc5
24
main.go
24
main.go
|
@ -5,10 +5,12 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -113,8 +115,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
||||||
|
|
||||||
if s.DefaultLanguage != domain.LanguageUnd {
|
if s.DefaultLanguage != domain.LanguageUnd {
|
||||||
supported = append(
|
supported = append(
|
||||||
[]language.Tag{language.Make(s.DefaultLanguage.Code())},
|
[]language.Tag{language.Make(s.DefaultLanguage.Code())}, supported...,
|
||||||
supported...,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +164,24 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue