Custom locations: exteding config generator
This commit is contained in:
parent
5fb2a08212
commit
9734b3d5c4
2 changed files with 51 additions and 16 deletions
|
@ -127,6 +127,27 @@ const internalNginx = {
|
||||||
return '/data/nginx/' + host_type + '/' + host_id + '.conf';
|
return '/data/nginx/' + host_type + '/' + host_id + '.conf';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderLocations: (host) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const tpl = `
|
||||||
|
location {{ path }} {
|
||||||
|
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port: }};
|
||||||
|
{{ advanced_config }}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locationRendering().then(() => resolve(renderedLocations));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} host_type
|
* @param {String} host_type
|
||||||
* @param {Object} host
|
* @param {Object} host
|
||||||
|
@ -153,24 +174,36 @@ const internalNginx = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderEngine
|
let locationsPromise;
|
||||||
.parseAndRender(template, host)
|
|
||||||
.then(config_text => {
|
|
||||||
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
|
|
||||||
|
|
||||||
if (debug_mode) {
|
if (host.locations) {
|
||||||
logger.success('Wrote config:', filename, config_text);
|
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
|
||||||
}
|
host.locations = renderedLocations;
|
||||||
|
|
||||||
resolve(true);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
if (debug_mode) {
|
|
||||||
logger.warn('Could not write ' + filename + ':', err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(new error.ConfigurationError(err.message));
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
locationsPromise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
locationsPromise.then(() => {
|
||||||
|
renderEngine
|
||||||
|
.parseAndRender(template, host)
|
||||||
|
.then(config_text => {
|
||||||
|
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
|
||||||
|
|
||||||
|
if (debug_mode) {
|
||||||
|
logger.success('Wrote config:', filename, config_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (debug_mode) {
|
||||||
|
logger.warn('Could not write ' + filename + ':', err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
reject(new error.ConfigurationError(err.message));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ server {
|
||||||
|
|
||||||
{{ advanced_config }}
|
{{ advanced_config }}
|
||||||
|
|
||||||
|
{{ locations }}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
{%- if access_list_id > 0 -%}
|
{%- if access_list_id > 0 -%}
|
||||||
# Access List
|
# Access List
|
||||||
|
|
Loading…
Reference in a new issue