Merge branch 'develop' into dist/ubuntu/bionic/develop

This commit is contained in:
wpetit 2021-01-15 16:32:30 +01:00
commit ef4d5efd02
8 changed files with 31 additions and 15 deletions

View File

@ -16,17 +16,16 @@ docker-image:
docker-run: docker-run:
docker run \ docker run \
--rm -it \ --rm -it \
-p 8080:8080 \ -p 3000:3000 \
-p 2525:2525 \
--tmpfs /app/data \ --tmpfs /app/data \
fake-sms:latest fake-sms:latest
docker-release: docker-release:
docker tag fake-sms:latest bornholm/fake-sms:latest docker tag fake-sms:latest cadoles/fake-sms:latest
docker tag fake-sms:latest bornholm/fake-sms:$(DOCKER_DATE_TAG) docker tag fake-sms:latest cadoles/fake-sms:$(DOCKER_DATE_TAG)
docker login docker login
docker push bornholm/fake-sms:latest docker push cadoles/fake-sms:latest
docker push bornholm/fake-sms:$(DOCKER_DATE_TAG) docker push cadoles/fake-sms:$(DOCKER_DATE_TAG)
test: test:
go test -v -race ./... go test -v -race ./...

View File

@ -7,7 +7,7 @@ Serveur d'envoi de SMS factice pour le développement avec interface web.
### Avec Docker ### Avec Docker
```bash ```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/. L'interface Web sera accessible à l'adresse http://localhost:3000/.

View File

@ -6,10 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{block "title" . -}}{{- end}}</title> <title>{{block "title" . -}}{{- end}}</title>
{{- block "head_style" . -}} {{- block "head_style" . -}}
<link rel="stylesheet" href="/css/main.css" /> <link rel="stylesheet" href="{{ .BaseUrl }}/css/main.css" />
{{end}} {{end}}
{{- block "head_script" . -}} {{- block "head_script" . -}}
<script type="text/javascript" src="/main.js"></script> <script type="text/javascript" src="{{ .BaseUrl }}/main.js"></script>
{{end}} {{end}}
</head> </head>
<body> <body>

View File

@ -2,7 +2,7 @@
<div class="columns is-mobile"> <div class="columns is-mobile">
<div class="column is-narrow"> <div class="column is-narrow">
<h1 class="is-size-3 title"> <h1 class="is-size-3 title">
<a href="/" rel="Inbox" class="has-text-grey-dark"> <a href="{{ .BaseUrl }}" rel="Inbox" class="has-text-grey-dark">
{{if or .Messages .SMS}} {{if or .Messages .SMS}}
📳 📳
{{else}} {{else}}

View File

@ -2,7 +2,7 @@
{{define "header_buttons"}} {{define "header_buttons"}}
<button <button
data-controller="restful" data-controller="restful"
data-restful-endpoint="/sms" data-restful-endpoint="{{ .BaseUrl }}/sms"
data-restful-method="DELETE" data-restful-method="DELETE"
class="button is-danger"> class="button is-danger">
🗑️ Clear 🗑️ Clear
@ -26,7 +26,7 @@
{{range .Messages}} {{range .Messages}}
<tr data-controller="inbox-entry" <tr data-controller="inbox-entry"
data-action="click->outbox-entry#onClick" data-action="click->outbox-entry#onClick"
data-inbox-entry-link="./sms/{{ .ID }}"> data-inbox-entry-link="{{ .BaseUrl }}/sms/{{ .ID }}">
<td class="sms-from"> <td class="sms-from">
<span class="is-size-7">{{ .From }}</span> <span class="is-size-7">{{ .From }}</span>
</td> </td>
@ -38,7 +38,7 @@
</td> </td>
<td class="sms-actions"> <td class="sms-actions">
<div class="buttons is-right"> <div class="buttons is-right">
<a href="./sms/{{ .ID }}" class="button is-small is-link">👁️ See</a> <a href="{{ .BaseUrl }}/sms/{{ .ID }}" class="button is-small is-link">👁️ See</a>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -2,9 +2,9 @@
{{define "header_buttons"}} {{define "header_buttons"}}
<button class="button is-danger" <button class="button is-danger"
data-controller="restful" data-controller="restful"
data-restful-endpoint="./{{ .SMS.ID }}" data-restful-endpoint="{{ .BaseUrl }}/{{ .SMS.ID }}"
data-restful-method="DELETE" data-restful-method="DELETE"
data-restful-redirect="../"> data-restful-redirect="{{ .BaseUrl }}">
🗑️ Delete 🗑️ Delete
</button> </button>
{{end}} {{end}}

View File

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

View File

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