better host upstream support

This commit is contained in:
Jamie Curnow 2023-01-09 13:18:11 +10:00
parent 0a50672ab6
commit ca4d92d793
6 changed files with 30 additions and 7 deletions

View File

@ -215,8 +215,6 @@ server {
# default location:
location / {
proxy_http_version 1.1;
{{#if Host.AccessListID}}
# Authorization
auth_basic ""Authorization required"";
@ -248,6 +246,7 @@ server {
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
{{#if Upstream.ID}}
# upstream

View File

@ -87,6 +87,11 @@ func CreateHost() func(http.ResponseWriter, *http.Request) {
return
}
if newHost.UpstreamID > 0 {
// nolint: errcheck, gosec
newHost.Expand([]string{"upstream"})
}
configureHost(newHost)
h.ResultResponseJSON(w, r, http.StatusOK, newHost)

View File

@ -38,6 +38,9 @@ func create(host *Model) (int, error) {
listen_interface,
domain_names,
upstream_id,
proxy_scheme,
proxy_host,
proxy_port,
certificate_id,
access_list_id,
ssl_forced,
@ -62,6 +65,9 @@ func create(host *Model) (int, error) {
:listen_interface,
:domain_names,
:upstream_id,
:proxy_scheme,
:proxy_host,
:proxy_port,
:certificate_id,
:access_list_id,
:ssl_forced,
@ -112,6 +118,9 @@ func update(host *Model) error {
listen_interface = :listen_interface,
domain_names = :domain_names,
upstream_id = :upstream_id,
proxy_scheme = :proxy_scheme,
proxy_host = :proxy_host,
proxy_port = :proxy_port,
certificate_id = :certificate_id,
access_list_id = :access_list_id,
ssl_forced = :ssl_forced,

View File

@ -58,7 +58,7 @@ type Model struct {
Certificate *certificate.Model `json:"certificate,omitempty"`
NginxTemplate *nginxtemplate.Model `json:"nginx_template,omitempty"`
User *user.Model `json:"user,omitempty"`
Upstream upstream.Model `json:"upstream,omitempty"`
Upstream *upstream.Model `json:"upstream,omitempty"`
}
func (m *Model) getByQuery(query string, params []interface{}) error {
@ -122,7 +122,7 @@ func (m *Model) Expand(items []string) error {
if m.UpstreamID > 0 {
var u upstream.Model
u, err = upstream.GetByID(m.UpstreamID)
m.Upstream = u
m.Upstream = &u
}
if util.SliceContainsItem(items, "user") && m.ID > 0 {
@ -146,7 +146,7 @@ func (m *Model) Expand(items []string) error {
if util.SliceContainsItem(items, "upstream") && m.UpstreamID > 0 {
var ups upstream.Model
ups, err = upstream.GetByID(m.UpstreamID)
m.Upstream = ups
m.Upstream = &ups
}
return err
@ -163,6 +163,9 @@ func (m *Model) GetTemplate() Template {
UserID: m.UserID,
Type: m.Type,
NginxTemplateID: m.NginxTemplateID,
ProxyScheme: m.ProxyScheme,
ProxyHost: m.ProxyHost,
ProxyPort: m.ProxyPort,
ListenInterface: m.ListenInterface,
DomainNames: domainNames,
UpstreamID: m.UpstreamID,
@ -180,7 +183,6 @@ func (m *Model) GetTemplate() Template {
Status: m.Status,
ErrorMessage: m.ErrorMessage,
IsDisabled: m.IsDisabled,
Upstream: m.Upstream,
}
return t

View File

@ -10,6 +10,9 @@ type Template struct {
UserID int
Type string
NginxTemplateID int
ProxyScheme string
ProxyHost string
ProxyPort int
ListenInterface string
DomainNames []string
UpstreamID int

View File

@ -30,6 +30,11 @@ func ConfigureHost(h host.Model) error {
certificateTemplate = h.Certificate.GetTemplate()
}
var ups upstream.Model
if h.Upstream != nil {
ups = *h.Upstream
}
data := TemplateData{
Certificate: certificateTemplate,
ConfDir: fmt.Sprintf("%s/nginx/hosts", config.Configuration.DataFolder),
@ -39,7 +44,7 @@ func ConfigureHost(h host.Model) error {
},
DataDir: config.Configuration.DataFolder,
Host: h.GetTemplate(),
Upstream: h.Upstream,
Upstream: ups,
}
removeHostFiles(h)