nginx-cf-realip
Version:
Command line utility for updating NGINX real-ip rules for CloudFlare's IPs
34 lines (33 loc) • 1.77 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const commander_1 = __importDefault(require("commander"));
const chalk_1 = __importDefault(require("chalk"));
const NginxRealip_1 = __importDefault(require("../NginxRealip"));
const realip = new NginxRealip_1.default();
const cli = commander_1.default
.option('-d, --destination <path>', 'Destination path for NGINX realip list.', './cf-realip.conf')
.option('-h, --header <header>', 'Header to fetch realip from.', 'CF-Connecting-IP')
.version(require('../../package.json').version)
.parse(process.argv);
realip.buildConfig(cli.header).then((config) => {
let path = path_1.default.resolve(cli.destination);
try {
if (fs_1.default.lstatSync(path).isDirectory()) {
path = path_1.default.join(path, 'cf-realip.conf');
}
}
catch (_a) { }
fs_1.default.writeFileSync(path, config);
console.log(chalk_1.default.green('\nAdded updated CloudFlare realip file to:'), path);
}).catch((exception) => {
console.debug(chalk_1.default.red(exception) + '\n');
console.error(chalk_1.default.bgRed(`Could not create NGINX realip file for the provided path`));
console.log(chalk_1.default.underline(cli.destination + '\n'));
console.log(`Check the destination path and try again. ${chalk_1.default.blue(`(Hint: Try to use just ${chalk_1.default.yellow('-p .')})`)}`);
console.log(`Use ${chalk_1.default.yellow('--help')} to view a list of options\n`);
});