unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
27 lines • 993 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const type_is_1 = require("type-is");
const DEFAULT_ACCEPTED_CONTENT_TYPE = 'application/json';
/**
* Builds an express middleware checking the content-type header
* returning 415 if the header is not either `application/json` or in the array
* passed into the function of valid content-types
* @param {String} acceptedContentTypes
* @returns {function(Request, Response, NextFunction): void}
*/
function requireContentType(...acceptedContentTypes) {
if (acceptedContentTypes.length === 0) {
acceptedContentTypes.push(DEFAULT_ACCEPTED_CONTENT_TYPE);
}
return (req, res, next) => {
const contentType = req.header('Content-Type');
if ((0, type_is_1.is)(contentType, acceptedContentTypes)) {
next();
}
else {
res.status(415).end();
}
};
}
exports.default = requireContentType;
//# sourceMappingURL=content_type_checker.js.map