All files / server/utils express.js

87.5% Statements 7/8
75% Branches 3/4
100% Functions 1/1
87.5% Lines 7/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34          1x 1x   1x               1x 46x       46x               1x        
/**
 * Express-related utilities.
 *
 * @module server/utils/express
 */
const config = require('../../config');
const log4js = require('log4js');
 
const logger = config.logger('express');
 
/**
 * Ensures that the specified object is an Express request, or throws an error.
 *
 * @param {Request} req - An Express request object.
 * @returns {Request} The first argument, unchanged.
 */
exports.ensureRequest = function(req) {
  Iif (!req || !req.app) {
    throw new Error('Argument must be an Express request');
  }
 
  return req;
};
 
/**
 * An Express middleware function that will log all HTTP requests.
 *
 * @function
 */
exports.logger = log4js.connectLogger(logger, {
  level: log4js.levels.TRACE,
  format: ':method :url :status :response-time ms'
});