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:
Varun Gupta
2023-12-02 19:13:47 -05:00
committed by Varun Gupta
parent 5586709d03
commit ec9eb0dd60
5 changed files with 80 additions and 82 deletions

View File

@@ -4,6 +4,7 @@ const execFile = require('child_process').execFile;
const { Liquid } = require('liquidjs');
const logger = require('../logger').global;
const error = require('./error');
const spawn = require('child_process').spawn;
module.exports = {
@@ -26,6 +27,37 @@ module.exports = {
return stdout;
},
/**
* Run the given command. Safer than using exec since args are passed as a list instead of in shell mode as a single string.
* @param {string} cmd The command to run
* @param {string} args The args to pass to the command
* @returns Promise that resolves to stdout or an object with error code and stderr if there's an error
*/
execSafe: (cmd, args) => {
return new Promise((resolve, reject) => {
let stdout = '';
let stderr = '';
const proc = spawn(cmd, args);
proc.stdout.on('data', (data) => {
stdout += data;
});
proc.stderr.on('data', (data) => {
stderr += data;
});
proc.on('close', (exitCode) => {
if (!exitCode) {
resolve(stdout.trim());
} else {
reject({
exitCode: exitCode,
stderr: stderr
});
}
});
});
},
/**
* @param {String} cmd
* @param {Array} args