Add BaseURL config parameter
This commit is contained in:
parent
61c3cd33be
commit
8027ba7bcc
|
@ -6,10 +6,10 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{block "title" . -}}{{- end}}</title>
|
||||
{{- block "head_style" . -}}
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
<link rel="stylesheet" href="{{ .BaseURL }}/css/main.css" />
|
||||
{{end}}
|
||||
{{- block "head_script" . -}}
|
||||
<script type="text/javascript" src="/main.js"></script>
|
||||
<script type="text/javascript" src="{{ .BaseURL }}/main.js"></script>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div class="columns is-mobile">
|
||||
<div class="column is-narrow">
|
||||
<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 .Emails .Email}}
|
||||
📬
|
||||
{{else}}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
{{define "header_buttons"}}
|
||||
<button class="button is-danger"
|
||||
data-controller="restful"
|
||||
data-restful-endpoint="./{{ .Email.ID }}"
|
||||
data-restful-endpoint="{{ .BaseURL }}/emails/{{ .Email.ID }}"
|
||||
data-restful-method="DELETE"
|
||||
data-restful-redirect="../">
|
||||
data-restful-redirect="{{ .BaseURL }}/">
|
||||
🗑️ Delete
|
||||
</button>
|
||||
{{end}}
|
||||
|
@ -24,8 +24,9 @@
|
|||
<h4 class="title is-size-4">Attachments ({{len .Email.Attachments}})</h4>
|
||||
<ul>
|
||||
{{ $email := .Email }}
|
||||
{{ $baseURL := .BaseURL }}
|
||||
{{range $i, $a := .Email.Attachments}}
|
||||
<li><a href="{{ $email.ID }}/attachments/{{ $i }}" download="{{ $a.Name }}">{{ $a.Name }}</a></li>
|
||||
<li><a href="{{ $baseURL }}/emails/{{ $email.ID }}/attachments/{{ $i }}" download="{{ $a.Name }}">{{ $a.Name }}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -44,7 +45,7 @@
|
|||
data-controller="iframe"
|
||||
data-action="load->iframe#onLoad"
|
||||
style="width:100%;{{if not .Email.HTML}}display:none;{{end}}"
|
||||
src="{{ .Email.ID }}/html">
|
||||
src="{{ .BaseURL }}/emails/{{ .Email.ID }}/html">
|
||||
</iframe>
|
||||
<div data-target="tabs.tabContent" data-tabs-for="text" style="{{if .Email.HTML}}display:none;{{end}}width:100%;overflow:hidden;">
|
||||
<pre style="white-space:pre-line;">{{ .Email.Text }}</pre>
|
||||
|
|
|
@ -24,10 +24,11 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ $baseURL := .BaseURL }}
|
||||
{{range .Emails}}
|
||||
<tr data-controller="inbox-entry"
|
||||
data-action="click->inbox-entry#onClick"
|
||||
data-inbox-entry-link="./emails/{{ .ID }}">
|
||||
data-inbox-entry-link="{{ $baseURL }}/emails/{{ .ID }}">
|
||||
<td class="email-subject"><div>{{ .Subject }}</div></td>
|
||||
<td class="email-from">
|
||||
{{range .From}}
|
||||
|
@ -44,7 +45,7 @@
|
|||
</td>
|
||||
<td class="email-actions">
|
||||
<div class="buttons is-right">
|
||||
<a href="./emails/{{ .ID }}" class="button is-small is-link">👁️ See</a>
|
||||
<a href="{{ $baseURL }}/emails/{{ .ID }}" class="button is-small is-link">👁️ See</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -22,6 +22,7 @@ type HTTPConfig struct {
|
|||
Address string `yaml:"address" env:"FAKESMTP_HTTP_ADDRESS"`
|
||||
TemplateDir string `yaml:"templateDir" env:"FAKESMTP_HTTP_TEMPLATEDIR"`
|
||||
PublicDir string `yaml:"publicDir" env:"FAKESMTP_HTTP_PUBLICDIR"`
|
||||
BaseURL string `yaml:"baseUrl" env:"FAKESMTP_HTTP_BASEURL"`
|
||||
}
|
||||
|
||||
type SMTPConfig struct {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue