"use strict";

/* eslint-disable global-require */

/**
 * Front-end middleware
 */
module.exports = function (app, options) {
  var isProd = process.env.NODE_ENV === 'production';

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

  var apiProxy = createProxyMiddleware('/CityInterface', {
    target: 'http://192.168.10.150:8050',
    // target: 'https://panda-water.cn',
    changeOrigin: true,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    pathRewrite: {
      '/CityInterface': '/CityInterface'
    }
  });
  var apiProxy2 = createProxyMiddleware('/cityinterface', {
    target: 'http://192.168.10.150:8050',
    // target: 'https://panda-water.cn',
    changeOrigin: true,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    pathRewrite: {
      '/cityinterface': '/cityinterface'
    }
  });

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

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

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

    app.use(apiProxy);
    app.use(apiProxy2);
    addDevMiddlewares(app, webpackConfig);
  }

  return app;
};