/* eslint-disable global-require */

/**
 * Front-end middleware
 */
module.exports = (app, options) => {
  const isProd = process.env.NODE_ENV === 'production';
  const { createProxyMiddleware } = require('http-proxy-middleware');
  const 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'
    }
});
const 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) {
    const addProdMiddlewares = require('./addProdMiddlewares');
    addProdMiddlewares(app, options);
  } else {
    const webpackConfig = require('../../internals/webpack/webpack.dev.babel');
    const addDevMiddlewares = require('./addDevMiddlewares');
    app.use(apiProxy)
    app.use(apiProxy2)
    addDevMiddlewares(app, webpackConfig);
  }

  return app;
};
