index.js 705 Bytes
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2
const utils = require('./util');
const createMiddleware = require('./createMiddleware');
3
const config = require('../../config/config');
邓晓峰's avatar
邓晓峰 committed
4
function mockMiddewares(req, res, next) {
5 6 7 8 9 10 11 12 13 14 15 16 17

  const ignore = [
    // ignore mock files under node_modules
    'node_modules/**',
    ...(config.mock && config.mock.exclude || []),
  ];


  const mockResult = utils.getMockData({
    cwd: process.cwd(),
    ignore
  });

邓晓峰's avatar
邓晓峰 committed
18 19 20
  const { middleware } = createMiddleware({
    ...mockResult,
    updateMockData: async () => {
21 22 23 24 25

      const result = utils.getMockData({
        cwd: process.cwd(),
        ignore
      });
邓晓峰's avatar
邓晓峰 committed
26 27 28 29 30 31 32
      return result;
    },
  });
  return middleware(req, res, next);
}

module.exports = mockMiddewares;