123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- 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());
- },
- };
- };
|