From be2febf0fe0e9e139524891bf1bc5318b6cc4465 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 22 Dec 2020 15:37:53 +0100 Subject: [PATCH 1/2] Transfer Docker image ownership to Cadoles --- Makefile | 11 +++++------ README.md | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 09bb89a..e66cee2 100644 --- a/Makefile +++ b/Makefile @@ -16,17 +16,16 @@ docker-image: docker-run: docker run \ --rm -it \ - -p 8080:8080 \ - -p 2525:2525 \ + -p 3000:3000 \ --tmpfs /app/data \ fake-sms:latest docker-release: - docker tag fake-sms:latest bornholm/fake-sms:latest - docker tag fake-sms:latest bornholm/fake-sms:$(DOCKER_DATE_TAG) + docker tag fake-sms:latest cadoles/fake-sms:latest + docker tag fake-sms:latest cadoles/fake-sms:$(DOCKER_DATE_TAG) docker login - docker push bornholm/fake-sms:latest - docker push bornholm/fake-sms:$(DOCKER_DATE_TAG) + docker push cadoles/fake-sms:latest + docker push cadoles/fake-sms:$(DOCKER_DATE_TAG) test: go test -v -race ./... diff --git a/README.md b/README.md index ae2ed26..c545146 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Serveur d'envoi de SMS factice pour le développement avec interface web. ### Avec Docker ```bash -docker run -it --rm -p 3000:3000 bornholm/fake-sms +docker run -it --rm -p 3000:3000 cadoles/fake-sms ``` L'interface Web sera accessible à l'adresse http://localhost:3000/. From 3020ab96b434be04518a4d86c1eb247880f46b1b Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 15 Jan 2021 16:28:45 +0100 Subject: [PATCH 2/2] Add BaseURL config parameter --- cmd/fake-sms/template/blocks/base.html.tmpl | 4 ++-- cmd/fake-sms/template/blocks/header.html.tmpl | 2 +- cmd/fake-sms/template/layouts/outbox.html.tmpl | 6 +++--- cmd/fake-sms/template/layouts/sms.html.tmpl | 4 ++-- internal/config/config.go | 1 + internal/route/helper.go | 16 ++++++++++++++++ 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cmd/fake-sms/template/blocks/base.html.tmpl b/cmd/fake-sms/template/blocks/base.html.tmpl index 343bd13..2f542cb 100644 --- a/cmd/fake-sms/template/blocks/base.html.tmpl +++ b/cmd/fake-sms/template/blocks/base.html.tmpl @@ -6,10 +6,10 @@ {{block "title" . -}}{{- end}} {{- block "head_style" . -}} - + {{end}} {{- block "head_script" . -}} - + {{end}} diff --git a/cmd/fake-sms/template/blocks/header.html.tmpl b/cmd/fake-sms/template/blocks/header.html.tmpl index 7c5f16c..322f7c1 100644 --- a/cmd/fake-sms/template/blocks/header.html.tmpl +++ b/cmd/fake-sms/template/blocks/header.html.tmpl @@ -2,7 +2,7 @@

- + {{if or .Messages .SMS}} 📳 {{else}} diff --git a/cmd/fake-sms/template/layouts/outbox.html.tmpl b/cmd/fake-sms/template/layouts/outbox.html.tmpl index 21fc14b..6193a9d 100644 --- a/cmd/fake-sms/template/layouts/outbox.html.tmpl +++ b/cmd/fake-sms/template/layouts/outbox.html.tmpl @@ -2,7 +2,7 @@ {{define "header_buttons"}} {{end}} diff --git a/internal/config/config.go b/internal/config/config.go index 9f61720..79b4fc7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 { diff --git a/internal/route/helper.go b/internal/route/helper.go index 5639808..877272c 100644 --- a/internal/route/helper.go +++ b/internal/route/helper.go @@ -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")