UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

39 lines (32 loc) 765 B
import bodyParser from 'body-parser'; import { match } from 'path-to-regexp'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * Body parser middleware. * * @param {DevCmsConfig} config */ export default (config) => { const pathsToExclude = ['/connectors/cms/standard/proxy/:proxyName'].concat( config.bodyParserMiddlewareExcludePaths || [], ); const pathsToExcludeMatch = match(pathsToExclude, { end: false, }); const jsonBodyParser = bodyParser.json({ limit: config.bodyParserLimit, }); return (req, res, next) => { if (pathsToExcludeMatch(req.path)) { next(); return; } jsonBodyParser(req, res, (error) => { if (error) { res.status(500).end(); return; } next(); }); }; };