const utils = require('./util');
const createMiddleware = require('./createMiddleware');
const config = require('../../config/config');
function mockMiddewares(req, res, next) {

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


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

  const { middleware } = createMiddleware({
    ...mockResult,
    updateMockData: async () => {

      const result = utils.getMockData({
        cwd: process.cwd(),
        ignore
      });
      return result;
    },
  });
  return middleware(req, res, next);
}

module.exports = mockMiddewares;
