Add BaseURL config parameter

This commit is contained in:
2021-07-26 14:47:58 +02:00
parent 61c3cd33be
commit 8027ba7bcc
6 changed files with 28 additions and 10 deletions

View File

@ -5,9 +5,11 @@ import (
"strconv"
"time"
"forge.cadoles.com/wpetit/fake-smtp/internal/config"
"forge.cadoles.com/wpetit/fake-smtp/internal/query"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/middleware/container"
"gitlab.com/wpetit/goweb/service"
"gitlab.com/wpetit/goweb/service/template"
)
@ -15,8 +17,8 @@ func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Da
ctn := container.Must(r.Context())
data, err := template.Extend(data,
template.WithBuildInfo(w, r, ctn),
withBaseURL(ctn),
)
if err != nil {
panic(errors.Wrap(err, "could not extend template data"))
}
@ -104,3 +106,16 @@ func createInboxQueryFromRequest(r *http.Request) (*query.GetInboxRequest, error
return inboxRequest, nil
}
func withBaseURL(ctn *service.Container) template.DataExtFunc {
return func(data template.Data) (template.Data, error) {
conf, err := config.From(ctn)
if err != nil {
return nil, errors.WithStack(err)
}
data["BaseURL"] = conf.HTTP.BaseURL
return data, nil
}
}