diff --git a/mock/mock-server.js b/mock/mock-server.js index 806fdacc..cc33fd9d 100644 --- a/mock/mock-server.js +++ b/mock/mock-server.js @@ -1,11 +1,12 @@ const chokidar = require('chokidar') const bodyParser = require('body-parser') +const multer = require('multer') const chalk = require('chalk') const path = require('path') const Mock = require('mockjs') const mockDir = path.join(process.cwd(), 'mock') - +const upload = multer() function registerRoutes(app) { let mockLastIndex const { default: mocks } = require('./index.js') @@ -13,7 +14,11 @@ function registerRoutes(app) { return responseFake(route.url, route.type, route.response) }) for (const mock of mocksForServer) { - app[mock.type](mock.url, mock.response) + // parse app.body + // https://expressjs.com/en/4x/api.html#req.body + app[mock.type](mock.url, bodyParser.json(), bodyParser.urlencoded({ + extended: true + }), upload.any(), mock.response) mockLastIndex = app._router.stack.length } const mockRoutesLength = Object.keys(mocksForServer).length @@ -47,13 +52,6 @@ module.exports = app => { // es6 polyfill require('@babel/register') - // parse app.body - // https://expressjs.com/en/4x/api.html#req.body - app.use(bodyParser.json()) - app.use(bodyParser.urlencoded({ - extended: true - })) - const mockRoutes = registerRoutes(app) var mockRoutesLength = mockRoutes.mockRoutesLength var mockStartIndex = mockRoutes.mockStartIndex diff --git a/package.json b/package.json index 448d1ec3..430660c1 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "husky": "1.3.1", "lint-staged": "8.1.5", "mockjs": "1.0.1-beta3", + "multer": "^1.4.2", "node-sass": "^4.9.0", "plop": "2.3.0", "runjs": "^4.3.2",