Add BaseURL config parameter

This commit is contained in:
2021-01-15 16:28:45 +01:00
parent be2febf0fe
commit 067569e0c3
6 changed files with 25 additions and 8 deletions

View File

@ -20,6 +20,7 @@ type HTTPConfig struct {
Address string `yaml:"address" env:"FAKESMS_HTTP_ADDRESS"`
TemplateDir string `yaml:"templateDir" env:"FAKESMS_HTTP_TEMPLATEDIR"`
PublicDir string `yaml:"publicDir" env:"FAKESMS_HTTP_PUBLICDIR"`
BaseURL string `yaml:"baseUrl" env:"FAKESMS_HTTP_BASEURL"`
}
type DataConfig struct {

View File

@ -5,9 +5,11 @@ import (
"strconv"
"time"
"forge.cadoles.com/Cadoles/fake-sms/internal/config"
"forge.cadoles.com/Cadoles/fake-sms/internal/query"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/middleware/container"
"gitlab.com/wpetit/goweb/service"
"gitlab.com/wpetit/goweb/service/template"
)
@ -15,6 +17,7 @@ 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 {
@ -24,6 +27,19 @@ func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Da
return data
}
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
}
}
func createOutboxQueryFromRequest(r *http.Request) (*query.GetOutboxRequest, error) {
orderBy := r.URL.Query().Get("orderBy")
reverse := r.URL.Query().Get("reverse")