Source: controllers/Technical.js

'use strict';

/**
 * @module controller
 * API controller for technical methods mapping.
 * @license MIT
 * @author Kai KRETSCHMANN <kai@kretschmann.consulting>
 */

const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = process.env.LOGLEVEL || "warn";

const utils = require('../utils/writer.js');
const feature = require('../utils/feature.js');
const eventEmitter = require('../utils/eventer').em;


/**
 * @method
 * Reply with pong on ping.
 * @public
 */
module.exports.ping = function ping(req, res, next) {
    if(feature.isEnabled(req, 'apihit')) {
        eventEmitter.emit('apihit', req);
    }

    utils.writeText(res, "pong", 200);
    logger.debug('pong back');
};

/**
 * @method
 * Reply with OK.
 * @public
 */
module.exports.healthCheck = function healthCheck(req, res, next) {
    if(feature.isEnabled(req, 'apihit')) {
        eventEmitter.emit('apihit', req);
    }

    utils.writeText(res, "OK", 200);
};