const _ = require('lodash'); const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'); const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'); const paths = require('./paths'); const path = require('path'); const express = require('express'); const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const hostt = process.env.HOST || '0.0.0.0'; let apiRootPath = process.env._SETTING_API_BASE_PATH || ''; if (!_.startsWith(apiRootPath, '/')) { apiRootPath = '/' + apiRootPath; } const contextPath = process.env._SETTING_CONTEXT_PATH; /* eslint-disable func-names */ module.exports = function(proxy, allowedHost) { return { port: 3000, // 禁止主机检测,不检查主机的应用程序容易受到DNS重新绑定攻击 disableHostCheck: true, // 启用gzip 压缩 compress: true, clientLogLevel: 'none', // 提供静态内容的服务目录 contentBase: paths.appPublic, // 静态内容服务目录文件变更时,触发页面重新加载 watchContentBase: true, // 启用 webpack 的模块热替换特性 hot: true, publicPath: _.isEmpty(contextPath) ? '' : `/${contextPath}/`, // 除了初始启动信息之外的任何内容都不会被打印到控制台。 webpack 的错误或警告在控制台不可见 quiet: true, progress: true, watchOptions: { ignored: /node_modules/, }, // 在响应中添加Header内容: headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS', 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization', }, https: protocol === 'https', host: hostt, overlay: false, historyApiFallback: { verbose: false, disableDotRule: true, index: _.isEmpty(contextPath) ? '/' : `/${contextPath}/`, }, public: allowedHost, proxy: process.env._SETTING_ENABLE_PROXY_API ? { [`${apiRootPath}bc/**`]: { target: process.env._SETTING_SERVER_PROXY_BC, changeOrigin: true, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_BC && { pathRewrite: { [`^${apiRootPath}bc/`]: '/', }, }), secure: false, // logLevel: 'debug', }, [`${apiRootPath}uc/**`]: { target: process.env._SETTING_SERVER_PROXY_UC, changeOrigin: true, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_UC && { pathRewrite: { [`^${apiRootPath}uc/`]: `/`, }, }), secure: false, // logLevel: 'debug', }, [`${apiRootPath}uc/oauth/zj4a/login`]: { target: process.env._SETTING_LOGIN_URL, changeOrigin: true, secure: false, }, [`${apiRootPath}dsem/**`]: { target: process.env._SETTING_SERVER_PROXY_DSEM, changeOrigin: true, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_DSEM && { // pathRewrite: { // [`^${apiRootPath}dsem/`]: '/', // }, }), secure: false, // logLevel: 'debug', }, [`${apiRootPath}login/**`]: { target: process.env._SETTING_SERVER_PROXY, changeOrigin: true, secure: false, // logLevel: 'debug', }, [`${apiRootPath}ocr/**`]: { target: process.env._SETTING_SERVER_PROXY_OCR, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_OCR && { pathRewrite: { [`^${apiRootPath}ocr/`]: '/', }, }), }, [`${apiRootPath}appscene/**`]: { target: process.env._SETTING_SERVER_PROXY_APPSCENE, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_APPSCENE && { pathRewrite: { [`^${apiRootPath}appscene/`]: '/', }, }), }, [`${apiRootPath}ammc/**`]: { target: process.env._SETTING_SERVER_PROXY_REPO, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_REPO && { pathRewrite: { [`^${apiRootPath}ammc/`]: '/', }, }), }, [`${apiRootPath}soc/**`]: { target: process.env._SETTING_SERVER_PROXY_SC, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_SC && { pathRewrite: { [`^${apiRootPath}soc/`]: '/', }, }), }, [`${apiRootPath}sic/**`]: { target: process.env._SETTING_SERVER_PROXY_SIC, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_SIC && { pathRewrite: { [`^${apiRootPath}sic/`]: '/', }, }), }, [`${apiRootPath}biz/**`]: { target: process.env._SETTING_SERVER_PROXY_OPT, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_OPT && { pathRewrite: { [`^${apiRootPath}biz/`]: '/', }, }), }, [`${apiRootPath}rcc/**`]: { target: process.env._SETTING_SERVER_PROXY_RES, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_RES && { pathRewrite: { [`^${apiRootPath}rcc/`]: '/', }, }), }, [`${apiRootPath}anb/**`]: { target: process.env._SETTING_SERVER_PROXY_ANB, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_ANB && { pathRewrite: { [`^${apiRootPath}anb/`]: '/', }, }), }, [`${apiRootPath}scc/**`]: { target: process.env._SETTING_SERVER_PROXY_APIS, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_APIS && { pathRewrite: { [`^${apiRootPath}scc/`]: '/', }, }), }, [`${apiRootPath}mc/**`]: { target: process.env._SETTING_SERVER_PROXY_MC, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_MC && { pathRewrite: { [`^${apiRootPath}mc/`]: '/', }, }), }, [`${apiRootPath}project/**`]: { target: process.env._SETTING_SERVER_PROXY_PROJECT, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_PROJECT && { pathRewrite: { [`^${apiRootPath}project/`]: '/', }, }), }, [`${apiRootPath}route/**`]: { target: process.env._SETTING_SERVER_PROXY_ROUTE, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_ROUTE && { pathRewrite: { [`^${apiRootPath}route/`]: '/', }, }), }, [`${apiRootPath}upload/**`]: { target: process.env._SETTING_SERVER_PROXY_UPLOAD, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_UPLOAD && { pathRewrite: { [`^${apiRootPath}upload/`]: '/', }, }), }, [`${apiRootPath}codemodel/**`]: { target: process.env._SETTING_SERVER_PROXY_CODE_MODEL, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_CODE_MODEL && { pathRewrite: { [`^${apiRootPath}codemodel/`]: '/', }, }), }, [`${apiRootPath}learning/**`]: { target: process.env._SETTING_SERVER_PROXY_LEARN, changeOrigin: true, secure: false, ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_LEARN && { pathRewrite: { [`^${apiRootPath}learning/`]: '/', }, }), }, [`${apiRootPath}job-manage/**`]: { target: process.env._SETTING_SERVER_PROXY_OR, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_OR && { pathRewrite: { [`^${apiRootPath}job-manage/`]: '/', }, }), }, [`${apiRootPath}job-serve/**`]: { target: process.env._SETTING_SERVER_PROXY_JOBS_SERVE, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_JOBS_SERVE && { pathRewrite: { [`^${apiRootPath}job-serve/`]: '/', }, }), }, [`${apiRootPath}gitlab/**`]: { target: process.env._SETTING_SERVER_PROXY_NB_VIEW, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_NB_VIEW && { pathRewrite: { [`^${apiRootPath}gitlab/`]: '/', }, }), }, [`${apiRootPath}guide-train/**`]: { target: process.env._SETTING_SERVER_PROXY_GUIDE_TRAIN, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_GUIDE_TRAIN && { pathRewrite: { [`^${apiRootPath}guide-train/`]: '/', }, }), }, [`${apiRootPath}data-pre/**`]: { target: process.env._SETTING_SERVER_PROXY_DATA_PRE, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_DATA_PRE && { pathRewrite: { [`^${apiRootPath}data-pre/api/`]: '/', }, }), }, [`${apiRootPath}streaming-reasoning/**`]: { target: process.env._SETTING_SERVER_PROXY_STREAMING_REASONING, changeOrigin: true, secure: false, // logLevel: 'debug', ...(process.env._SETTING_SERVER_PROXY !== process.env._SETTING_SERVER_PROXY_STREAMING_REASONING && { pathRewrite: { [`^${apiRootPath}streaming-reasoning/`]: '/', }, }), }, } : {}, before(app) { if (!_.isEmpty(contextPath)) { app.use(`/${contextPath}/images`, express.static(path.join(paths.appPublic, 'images'))); app.use(`/${contextPath}/docs`, express.static(path.join(paths.appPublic, 'docs'))); } app.use(errorOverlayMiddleware()); app.use(noopServiceWorkerMiddleware()); }, }; };