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