Custom locations: exteding config generator

This commit is contained in:
Laszlo Ancsin 2019-02-18 22:08:02 +01:00
parent 5fb2a08212
commit 9734b3d5c4
2 changed files with 51 additions and 16 deletions

View file

@ -127,6 +127,27 @@ const internalNginx = {
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 {Object} host
@ -153,6 +174,17 @@ const internalNginx = {
return;
}
let locationsPromise;
if (host.locations) {
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
host.locations = renderedLocations;
});
} else {
locationsPromise = Promise.resolve();
}
locationsPromise.then(() => {
renderEngine
.parseAndRender(template, host)
.then(config_text => {
@ -172,6 +204,7 @@ const internalNginx = {
reject(new error.ConfigurationError(err.message));
});
});
});
},
/**

View file

@ -15,6 +15,8 @@ server {
{{ advanced_config }}
{{ locations }}
location / {
{%- if access_list_id > 0 -%}
# Access List