配置文件
UI 应用
config/config.ts
// 注意!!修改该配置文件不会热更新,需要重新执行npm start
const npmScope = ''; // 私有npm依赖的scope
const isDev = process.env.NODE_ENV === 'development';
const config:IConfig = {
chainWebpack: webpackConfig => {}, // webpack配置修改
enableElectron: false, // 是否使用Electron客户端
devServerPort: 8888, // dev server 端口
devThemeServerPort: 9999, // 主题开发dev server端口
isScaffoldApp: false, // 是否是脚手架
isPortal: false, // 是否是Portal应用(主应用)
copyWebpack: [], // 详细使用参考: https://www.npmjs.com/package/copy-webpack-plugin
apiConfig: {
isDebug: isDev,
proxyServer: '/',
base: isDev ? 'http://127.0.0.1:8889' : '', // BFF地址
domain: {// 不经过BFF转发配置,一般正式环境不要配置
'/auth': 'http://127.0.0.1:8080/auth' // 例如这里配置/auth接口转发到http://127.0.0.1:8080/auth服务
},
serviceProxyEnv: isDev // 服务代理环境(默认是default)
? {
auth: 'test' // 例如这里配置auth服务转发到test环境
}
: {}
},
definePlugin: {
ENABLE_SSO: false, // 正式环境是否只允许SSO登录
APP_ID: JSON.stringify('pro'), // 应用ID
ENABLE_WEBSOCKET: false, // 是否支持websocket
PROJECT_NAME: JSON.stringify('Godzilla Scaffold') // 应用名称
},
npmScope,
resolveAlias: npmScope
? {
'quantex-utils': `${npmScope}/quantex-utils`,
'quantex-design': `${npmScope}/quantex-design`,
'quantex-scripts': `${npmScope}/quantex-scripts`
}
: {},
godzillaLicenseKey:'', // godzilla license
agGridLicenseKey:'', // ag grid license
themeConfig: {
defaultTheme: 'themeDark',
mainTheme: 'themeDark',
themes: [
{
name: '深色',
id: 'themeDark',
},
{
name: '浅色',
id: 'themeWhite',
},
],
},
plugins: [ // 插件配置
[
'metrics', // 埋点插件
{
enable: true,
domain: 'http://10.16.18.166:32143',
url: '/api/v1/metrics',
method: 'POST',
env: 'DEV', // ST、UAT、PRD等
reportInterval: 10 * 1000, // 一分钟上报一次
package: '@gza/quantex-plugin-metrics',
},
],
[
'theme-dark', // 主题插件
{
enable: true,
package: '@gza/quantex-plugin-theme-dark',
},
]
],
};
BFF 应用
config/config.default.js
const path = require('path');
export default (appInfo: any) => {
const config: any = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1580801423078_9403';
// add your config here
config.middleware = ['logger', 'staticAssetProxy', 'notfoundHandler', 'authentication', 'apiProxy'];
//if (process.env.NODE_ENV === 'development') {
// config.middleware.push('rap'); // RAP代理
config.middleware.push('mockdata'); // mockjs代理
//}
// CSRF配置
config.security = {
csrf: {
enable: false
}
};
// API代理
config.apiProxy = {
// refreshInterval: '10m', // 每隔10分钟刷新代理配置
// persistOperationLogInterval: '1m', // 每隔1分钟持久化操作日志
base: `http://127.0.0.1:${process.env.PORT}`,
domain: {
'/sample': { default: process.env.SAMPLE_SERVICE }
}
};
// 安全认证拦截器
config.authentication = {
secret: 'quantex',
redirectUrl: process.env.REDIRECT_URL
};
// 跨域配置 1. 允许跨域,2.允许跨域并且携带cookie,参考:https://github.com/eggjs/egg-cors
config.cors = {
origin: ctx => {
// https://github.com/koajs/cors/issues/52
// 在开发模式下,允许跨域访问
// TODO 在生产模式下,允许指定域名访问
// TODO 其它情况,不允许跨域访问
// 在开发模式下,动态返回origin
return ctx.request.header.origin;
},
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
credentials: true
};
// 静态资源映射,目前主要服务于mock配置页面=>http://localhost:8889/mock
config.static = {
dir: [
path.join(appInfo.baseDir, 'app/public'),
{ prefix: '/mock/mockjs', dir: path.join(process.cwd(), 'node_modules/mockjs') },
{ prefix: '/mock/vue', dir: path.join(process.cwd(), 'node_modules/vue') },
{ prefix: '/mock/element-ui', dir: path.join(process.cwd(), 'node_modules/element-ui') }
]
};
// 统一异常处理 https://eggjs.org/zh-cn/core/error-handling.html
config.onerror = {
all(err, ctx) {
// 在此处定义针对所有响应类型的错误处理方法
// 注意,定义了 config.all 之后,其他错误处理方法不会再生效
if (ctx.request.headers['content-type'] && ctx.request.headers['content-type'].includes('application/json')) {
ctx.body = JSON.stringify({ code: 500, msg: err.message, msgDetail: err.stack });
ctx.status = 200;
} else {
ctx.body = 'error';
ctx.status = 500;
}
console.error(err.stack);
}
};
// 静态资源转发
config.staticAssetProxy = {
ssoLoginUrl: process.env.SSO_LOGIN_URL,
ssoLogoutUrl: process.env.SSO_LOGOUT_URL,
redirectUrl: process.env.REDIRECT_URL
};
// session配置
config.session = {
key: 'EGG_SESS',
maxAge: 24 * 3600 * 1000, // 1 天
httpOnly: false,
encrypt: true
};
// 将日志打印到终端(并且不会写入文件)
config.logger = {
level: 'NONE',
consoleLevel: 'INFO',
disableConsoleAfterReady: false
};
// 监听文件变化realod
config.development = {
watchDirs: ['src/lib']
};
return config;
};
npm run dev | npm run start 环境变量
REDIRECT_URL
SSO 登录成功后重定向地址,一般指向 portal 主应用地址PUBKEY_NAME
SSO 验证 token 的私钥PORT
启动服务的端口SSO_LOGIN_URL
SSO 登录地址SSO_LOGOUT_URL
SSO 登出地址SAMPLE_SERVICE
sample 服务地址