UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

40 lines (33 loc) 773 B
import multer from 'multer'; import os from 'os'; import { match } from 'path-to-regexp'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * Upload middleware for sending files to our routes. * * @param {DevCmsConfig} config */ export default (config) => { const pathsToExclude = ['/connectors/cms/standard/proxy/:proxyName'].concat( config.bodyParserMiddlewareExcludePaths || [], ); const pathsToExcludeMatch = match(pathsToExclude, { end: false, }); const upload = multer({ dest: os.tmpdir(), }).any(); return (req, res, next) => { if (pathsToExcludeMatch(req.path)) { next(); return; } upload(req, res, (error) => { if (error) { res.status(500).end(); return; } next(); }); }; };