Custom locations bugfix
This commit is contained in:
parent
b04e9fa04d
commit
f44f635e5c
5 changed files with 31 additions and 11 deletions
|
@ -127,20 +127,28 @@ const internalNginx = {
|
|||
return '/data/nginx/' + host_type + '/' + host_id + '.conf';
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates custom locations
|
||||
* @param {Object} host
|
||||
* @returns {Promise}
|
||||
*/
|
||||
renderLocations: (host) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const tpl = `
|
||||
location {{ path }} {
|
||||
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port: }};
|
||||
{{ advanced_config }}
|
||||
}
|
||||
`;
|
||||
let template;
|
||||
|
||||
try {
|
||||
template = fs.readFileSync(__dirname + '/../templates/_location.conf', {encoding: 'utf8'});
|
||||
} catch (err) {
|
||||
reject(new error.ConfigurationError(err.message));
|
||||
return;
|
||||
}
|
||||
|
||||
let renderer = new Liquid();
|
||||
let renderedLocations = '';
|
||||
|
||||
const locationRendering = async () => {
|
||||
for (let i = 0; i < host.locations.length; i++) {
|
||||
renderedLocations += await renderer.parseAndRender(tpl, host.locations[i]);
|
||||
renderedLocations += await renderer.parseAndRender(template, host.locations[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,8 +183,10 @@ const internalNginx = {
|
|||
}
|
||||
|
||||
let locationsPromise;
|
||||
let origLocations;
|
||||
|
||||
if (host.locations) {
|
||||
origLocations = [].concat(host.locations);
|
||||
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
|
||||
host.locations = renderedLocations;
|
||||
});
|
||||
|
@ -194,6 +204,9 @@ const internalNginx = {
|
|||
logger.success('Wrote config:', filename, config_text);
|
||||
}
|
||||
|
||||
// Restore locations array
|
||||
host.locations = origLocations;
|
||||
|
||||
resolve(true);
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
|
@ -26,9 +26,6 @@ class ProxyHost extends Model {
|
|||
this.meta = {};
|
||||
}
|
||||
|
||||
// Serialize custom locations
|
||||
this.locations = JSON.stringify(this.locations);
|
||||
|
||||
this.domain_names.sort();
|
||||
}
|
||||
|
||||
|
|
8
src/backend/templates/_location.conf
Normal file
8
src/backend/templates/_location.conf
Normal file
|
@ -0,0 +1,8 @@
|
|||
location {{ path }} {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Scheme $scheme;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port: }};
|
||||
{{ advanced_config }}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
<div class="tab-pane" id="locations">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<button type="button" class="btn btn-secondary add_location">Add location</button>
|
||||
<button type="button" class="btn btn-secondary add_location"><%- i18n('locations', 'new_location') %></button>
|
||||
<div class="locations_container mt-3"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -240,6 +240,8 @@ module.exports = Mn.View.extend({
|
|||
this.model = new ProxyHostModel.Model();
|
||||
}
|
||||
|
||||
this.locationsCollection = new ProxyLocationModel.Collection();
|
||||
|
||||
// Custom locations
|
||||
this.showChildView('locations_regions', new CustomLocation.LocationCollectionView({
|
||||
collection: this.locationsCollection
|
||||
|
|
Loading…
Reference in a new issue