"use strict";

/* eslint-disable global-require */

/**
 * Front-end middleware
 */
var proxyConfig = require('../../config/proxy');

var fs = require('fs');

var path = require('path');

var apiMocker = require('connect-api-mocker');

module.exports = function (app, options) {
  var isProd = process.env.NODE_ENV === 'production';

  var _require = require('http-proxy-middleware'),
      createProxyMiddleware = _require.createProxyMiddleware;

  if (isProd) {
    var addProdMiddlewares = require('./addProdMiddlewares');

    addProdMiddlewares(app, options);
  } else {
    var webpackConfig = require('../../internals/webpack/webpack.dev.babel');

    var addDevMiddlewares = require('./addDevMiddlewares');

    Object.keys(proxyConfig.dev).forEach(function (item) {
      app.use(createProxyMiddleware(item, proxyConfig.dev[item]));
    });
    addDevMiddlewares(app, webpackConfig);
  }

  return app;
};