mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 10:06:26 +00:00
Use upstream in host config
This commit is contained in:
@ -14,7 +14,7 @@ import (
|
||||
// ConfigureHost will attempt to write nginx conf and reload nginx
|
||||
func ConfigureHost(h host.Model) error {
|
||||
// nolint: errcheck, gosec
|
||||
h.Expand([]string{"certificate", "nginxtemplate"})
|
||||
h.Expand([]string{"certificate", "nginxtemplate", "upstream"})
|
||||
|
||||
var certificateTemplate certificate.Template
|
||||
if h.Certificate != nil {
|
||||
@ -22,10 +22,15 @@ func ConfigureHost(h host.Model) error {
|
||||
}
|
||||
|
||||
data := TemplateData{
|
||||
ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder),
|
||||
DataDir: config.Configuration.DataFolder,
|
||||
Host: h.GetTemplate(),
|
||||
Certificate: certificateTemplate,
|
||||
ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder),
|
||||
Config: Config{ // todo
|
||||
Ipv4: true,
|
||||
Ipv6: false,
|
||||
},
|
||||
DataDir: config.Configuration.DataFolder,
|
||||
Host: h.GetTemplate(),
|
||||
Upstream: h.Upstream,
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("%s/host_%d.conf", data.ConfDir, h.ID)
|
||||
|
@ -92,7 +92,7 @@ server {
|
||||
Certificate: test.cert.GetTemplate(),
|
||||
}
|
||||
|
||||
output, err := generateHostConfig(template, templateData)
|
||||
output, err := renderTemplate(template, templateData)
|
||||
assert.Equal(t, test.want.err, err)
|
||||
assert.Equal(t, test.want.output, output)
|
||||
})
|
||||
|
@ -13,25 +13,29 @@ import (
|
||||
"github.com/aymerick/raymond"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Ipv4 bool
|
||||
Ipv6 bool
|
||||
}
|
||||
|
||||
// TemplateData is a struct
|
||||
type TemplateData struct {
|
||||
ConfDir string
|
||||
Config Config
|
||||
DataDir string
|
||||
Host host.Template
|
||||
Certificate certificate.Template
|
||||
Upstream upstream.Model
|
||||
}
|
||||
|
||||
func generateHostConfig(template string, data TemplateData) (string, error) {
|
||||
func renderTemplate(template string, data TemplateData) (string, error) {
|
||||
logger.Debug("Rendering Template - Template: %s", template)
|
||||
logger.Debug("Rendering Template - Data: %+v", data)
|
||||
return raymond.Render(template, data)
|
||||
|
||||
// todo: apply some post processing to this config, stripe trailing whitespace from lines and then remove groups of 2+ \n's so the config looks nicer
|
||||
}
|
||||
|
||||
func writeTemplate(filename, template string, data TemplateData) error {
|
||||
output, err := generateHostConfig(template, data)
|
||||
output, err := renderTemplate(template, data)
|
||||
if err != nil {
|
||||
output = fmt.Sprintf("# Template Error: %s", err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user