fixed padding and syntax

This commit is contained in:
Luca Wlcek
2023-11-17 16:19:31 +01:00
parent c91084b956
commit 676db1cac1

View File

@@ -1,10 +1,10 @@
const _ = require('lodash'); const _ = require('lodash');
const fs = require('fs'); const fs = require('fs');
const logger = require('../logger').nginx; const logger = require('../logger').nginx;
const config = require('../lib/config'); const config = require('../lib/config');
const utils = require('../lib/utils'); const utils = require('../lib/utils');
const error = require('../lib/error'); const error = require('../lib/error');
const passthroughHostModel = require('../models/ssl_passthrough_host'); const passthroughHostModel = require('../models/ssl_passthrough_host');
const internalNginx = { const internalNginx = {
@@ -250,68 +250,68 @@ const internalNginx = {
return; return;
} }
let locationsPromise; let locationsPromise;
let origLocations; let origLocations;
// Manipulate the data a bit before sending it to the template // Manipulate the data a bit before sending it to the template
if (host_type === 'ssl_passthrough_host') { if (host_type === 'ssl_passthrough_host') {
if (internalNginx.sslPassthroughEnabled()){ if (internalNginx.sslPassthroughEnabled()){
const allHosts = await passthroughHostModel const allHosts = await passthroughHostModel
.query() .query()
.where('is_deleted', 0) .where('is_deleted', 0)
.groupBy('id') .groupBy('id')
.omit(['is_deleted']); .omit(['is_deleted']);
host = { host = {
all_passthrough_hosts: allHosts.map((host) => { all_passthrough_hosts: allHosts.map((host) => {
// Replace dots in domain // Replace dots in domain
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host); host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
return host; return host;
}), }),
}; };
} else { } else {
internalNginx.deleteConfig(host_type, host, false); internalNginx.deleteConfig(host_type, host, false);
}
} else if (host_type !== 'default') {
host.use_default_location = true;
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
}
}
if (host.locations) {
//logger.info ('host.locations = ' + JSON.stringify(host.locations, null, 2));
origLocations = [].concat(host.locations);
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
host.locations = renderedLocations;
});
// Allow someone who is using / custom location path to use it, and skip the default / location
_.map(host.locations, (location) => {
if (location.path === '/') {
host.use_default_location = false;
} }
});
} else if (host_type !== 'default') {
host.use_default_location = true;
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
}
}
} else { if (host.locations) {
locationsPromise = Promise.resolve(); //logger.info ('host.locations = ' + JSON.stringify(host.locations, null, 2));
} origLocations = [].concat(host.locations);
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
host.locations = renderedLocations;
});
// Set the IPv6 setting for the host // Allow someone who is using / custom location path to use it, and skip the default / location
host.ipv6 = internalNginx.ipv6Enabled(); _.map(host.locations, (location) => {
if (location.path === '/') {
host.use_default_location = false;
}
});
return locationsPromise.then(() => { } else {
renderEngine locationsPromise = Promise.resolve();
.parseAndRender(template, host) }
.then((config_text) => {
fs.writeFileSync(filename, config_text, {encoding: 'utf8'}); // Set the IPv6 setting for the host
host.ipv6 = internalNginx.ipv6Enabled();
return locationsPromise.then(() => {
renderEngine
.parseAndRender(template, host)
.then((config_text) => {
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
if (config.debug()) { if (config.debug()) {
logger.success('Wrote config:', filename, config_text); logger.success('Wrote config:', filename, config_text);
} }
// Restore locations array // Restore locations array
host.locations = origLocations; host.locations = origLocations;
resolve(true); resolve(true);
}) })
@@ -320,9 +320,9 @@ const internalNginx = {
logger.warn('Could not write ' + filename + ':', err.message); logger.warn('Could not write ' + filename + ':', err.message);
} }
throw new error.ConfigurationError(err.message); throw new error.ConfigurationError(err.message);
}); });
}) });
}); });
}, },