diff --git a/Dockerfile b/Dockerfile index acc3d6c..fb21b1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,5 @@ FROM alpine:latest WORKDIR /app COPY --from=builder /app/teafolio /app/teafolio -COPY /static /app/static ENTRYPOINT [ "/app/teafolio" ] diff --git a/router.go b/router.go index be8c5a3..706aa41 100644 --- a/router.go +++ b/router.go @@ -1,6 +1,7 @@ package main import ( + "embed" "encoding/base64" "fmt" "net/http" @@ -8,6 +9,14 @@ import ( "strings" ) +//go:embed static/* +var StaticFiles embed.FS + +func (this *Application) ServeStatic(w http.ResponseWriter, r *http.Request) { + http.FileServer(http.FS(StaticFiles)).ServeHTTP(w, r) + // http.StripPrefix(`/static/`, http.FileServer(http.FS(StaticFiles))).ServeHTTP(w, r) +} + func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method == `GET` { if r.URL.Path == `/` { @@ -56,8 +65,9 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { this.Repopage(w, r, repoName) - } else if r.URL.Path == `/static/logo.png` { - if this.cfg.Template.CustomLogoPngBase64 != "" { + } else if strings.HasPrefix(r.URL.Path, `/static/`) { + + if r.URL.Path == `/static/logo.png` && this.cfg.Template.CustomLogoPngBase64 != "" { logoPng, err := base64.StdEncoding.DecodeString(this.cfg.Template.CustomLogoPngBase64) if err != nil { @@ -69,16 +79,12 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set(`Content-Type`, `image/png`) w.WriteHeader(200) w.Write(logoPng) - - } else { - r.URL.Path = r.URL.Path[8:] - http.FileServer(http.Dir(`static`)).ServeHTTP(w, r) - + return } - } else if strings.HasPrefix(r.URL.Path, `/static/`) { - r.URL.Path = r.URL.Path[8:] - http.FileServer(http.Dir(`static`)).ServeHTTP(w, r) + // Embedded resource + // r.URL.Path = r.URL.Path[8:] + this.ServeStatic(w, r) } else if r.URL.Query().Get("go-get") == "1" { // This wasn't one of our standard `/repo` paths, but there is the ?go-get=1 parameter