mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-23 20:35:46 +00:00
Refactor and integrate ddns resolution with nginx module
Refactored ddns resolver so that no patching is done. nginx.js will automatically resolve ddns addresses if needed. Added dedicated logger scope for ddns resovler.
This commit is contained in:
@ -4,6 +4,7 @@ const logger = require('../logger').nginx;
|
||||
const config = require('../lib/config');
|
||||
const utils = require('../lib/utils');
|
||||
const error = require('../lib/error');
|
||||
const ddnsResolver = require('../lib/ddns_resolver');
|
||||
|
||||
const internalNginx = {
|
||||
|
||||
@ -131,6 +132,31 @@ const internalNginx = {
|
||||
return '/data/nginx/' + internalNginx.getFileFriendlyHostType(host_type) + '/' + host_id + '.conf';
|
||||
},
|
||||
|
||||
/**
|
||||
* Resolves any ddns addresses that need to be resolved for clients in the host's access list.
|
||||
* @param {Object} host
|
||||
* @returns {Promise}
|
||||
*/
|
||||
resolveDDNSAddresses: (host) => {
|
||||
const promises = [];
|
||||
if (typeof host.access_list !== 'undefined' && typeof host.access_list.clients !== 'undefined') {
|
||||
for (const client of host.access_list.clients) {
|
||||
if (ddnsResolver.requiresResolution(client.address)) {
|
||||
const p = ddnsResolver.resolveAddress(client.address)
|
||||
.then((resolvedIP) => {
|
||||
client.address = `${resolvedIP}; # ${client.address}`;
|
||||
return Promise.resolve();
|
||||
});
|
||||
promises.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (promises.length) {
|
||||
return Promise.all(promises);
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates custom locations
|
||||
* @param {Object} host
|
||||
@ -201,6 +227,12 @@ const internalNginx = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve ddns addresses if needed
|
||||
let resolverPromise = Promise.resolve();
|
||||
if (host_type === 'proxy_host') {
|
||||
resolverPromise = internalNginx.resolveDDNSAddresses(host);
|
||||
}
|
||||
|
||||
let locationsPromise;
|
||||
let origLocations;
|
||||
|
||||
@ -215,8 +247,10 @@ const internalNginx = {
|
||||
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;
|
||||
locationsPromise = resolverPromise.then(() => {
|
||||
return internalNginx.renderLocations(host).then((renderedLocations) => {
|
||||
host.locations = renderedLocations;
|
||||
});
|
||||
});
|
||||
|
||||
// Allow someone who is using / custom location path to use it, and skip the default / location
|
||||
@ -227,7 +261,7 @@ const internalNginx = {
|
||||
});
|
||||
|
||||
} else {
|
||||
locationsPromise = Promise.resolve();
|
||||
locationsPromise = resolverPromise;
|
||||
}
|
||||
|
||||
// Set the IPv6 setting for the host
|
||||
|
Reference in New Issue
Block a user