leasehold-http-api
Version:
HTTP API module for Leasehold sidechain
54 lines (48 loc) • 1.52 kB
JavaScript
/*
* Copyright © 2019 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/
;
const debug = require('debug')('swagger:lisk:compression');
const _ = require('lodash');
const compression = require('compression');
/**
* Description of the function.
*
* @func create_compression
* @memberof api.fittings
* @requires compression
* @requires debug
* @requires lodash
* @param {Object} fittingDef
* @param {Object} bagpipes
* @returns {function} {@link api.fittings.lisk_compression}
* @todo Add description for the function and the params
*/
module.exports = function create(fittingDef) {
debug('config: %j', fittingDef);
const validCorsOptions = ['level', 'chunkSize', 'memLevel'];
const middleware = compression(_.pick(fittingDef, validCorsOptions));
/**
* Description of the function.
*
* @func lisk_compression
* @memberof api.fittings
* @param {Object} context
* @param {function} cb
* @todo Add description for the function and the params
*/
return function lisk_compression(context, cb) {
debug('exec');
middleware(context.request, context.response, cb);
};
};