1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00

Set base path in index.html (#172)

- Create a new index-dev.html for webpack live server
- Update Go+index.html to set <base href>
- Fixes #171
This commit is contained in:
James Hillyerd
2020-08-29 19:06:21 -07:00
committed by GitHub
parent 289b38f016
commit 5a0c4778cb
6 changed files with 75 additions and 4 deletions

View File

@@ -1,9 +1,11 @@
package web
import (
"html/template"
"net/http"
"os"
"github.com/inbucket/inbucket/pkg/config"
"github.com/rs/zerolog/log"
)
@@ -82,3 +84,21 @@ func requestLoggingWrapper(next http.Handler) http.Handler {
next.ServeHTTP(w, req)
})
}
// spaTemplateHandler creates a handler to serve the index.html template for our SPA.
func spaTemplateHandler(tmpl *template.Template, basePath string,
webConfig config.Web) http.Handler {
tmplData := struct {
BasePath string
}{
BasePath: basePath,
}
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
err := tmpl.Execute(w, tmplData)
if err != nil {
log.Error().Str("module", "web").Str("remote", req.RemoteAddr).Str("proto", req.Proto).
Str("method", req.Method).Str("path", req.RequestURI).Err(err).
Msg("Error rendering SPA index template")
}
})
}