private-route.js 562 Bytes
const _ = require('lodash');
const logger = global.yoho.logger;

module.exports = (req, res, next) => {
    try {
        const privateIps = _.get(req, 'app.locals.yap.json.privateips', []);

        if (_.includes(privateIps, req.yoho.clientIp) || _.get(req, 'app.locals.devEnv', false )
            || _.get(req, 'app.locals.isTest', false )) {
            return next();
        }
    } catch (error) {
        logger.error('[privateips error], ', error);
    }
    logger.warn(`[privateips warn], ${req.yoho.clientIp}`);
    return res.status(401).end();
};