Add BaseURL config parameter
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user