You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

131 lines
3.9 KiB

'use strict';
/*jslint node:true*/
const path = require('path');
/*这种以CommonJS的同步形式去引入其它模块的方式代码更加简洁:获取组件*/
const os = require('os');
const moment = require('moment');
const args = require('args');
const dev = process.env.NODE_ENV == 'development' || process.env.NODE_ENV == 'developmentVite';
const vite = process.env.NODE_ENV == 'developmentVite';
dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,维护良好的开发环境,媛猿有责');
// // 启动参数
args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiVcmpUrl', 'webapi的URL 外网可访问');
args.option('apiAuthUrl', 'IOT 鉴权 api');
args.option('apiAnxinyunUrl', '安心云 api');
args.option('iotAuthWeb', 'IOT 鉴权 web');
args.option('iotVideoServer', 'IOT 后端视频服务鉴权');
args.option('iotVideoPlayServer', 'IOT 后端视频播放服务');
const flags = args.parse(process.argv);
const API_URL = process.env.API_URL || flags.apiUrl;
const API_VCMP_URL = process.env.API_VCMP_URL || flags.apiVcmpUrl;
const API_AUTH_URL = process.env.API_AUTH_URL || flags.apiAuthUrl;
const IOT_AUTH_WEB = process.env.IOT_AUTH_WEB || flags.iotAuthWeb;
const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl;
const IOT_VIDEO_SERVER = process.env.IOT_VIDEO_SERVER || flags.iotVideoServer;
const IOT_VIDEO_PALY_SERVER = process.env.IOT_VIDEO_PALY_SERVER || flags.iotVideoPlayServer;
if (!API_URL || !API_ANXINYUN_URL || !API_AUTH_URL || !IOT_AUTH_WEB || !IOT_VIDEO_SERVER || !IOT_VIDEO_PALY_SERVER) {
console.log('缺少启动参数,异常退出');
args.showHelp();
process.exit(-1);
}
const product = {
port: flags.port || 8080,
staticDirs: [path.join(__dirname, './client')],
mws: [{
entry: require('./middlewares/proxy').entry,
opts: {
host: API_URL,
match: /^\/_api\//,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: API_AUTH_URL,
match: /^\/_auth\//,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: API_ANXINYUN_URL,
match: /^\/_axy\//,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: IOT_VIDEO_SERVER,
match: /^\/_vs\//,
}
}, {
// TODO 还不能用
entry: require('./middlewares/proxy').entry,
opts: {
host: 'https://open.ys7.com',
match: /^\/_yingshi\//,
}
}, {
entry: require('./routes').entry,
opts: {
apiUrl: API_VCMP_URL,
iotAuthWeb: IOT_AUTH_WEB,
iotVideoServer: IOT_VIDEO_SERVER,
iotVideoPlayServer: IOT_VIDEO_PALY_SERVER,
staticRoot: './client',
}
}, {
entry: require('./client').entry,// 静态信息
opts: {}
}],
logger: {
level: 'debug',
json: false,
filename: path.join(__dirname, 'log', 'runtime.txt'),
colorize: true,
maxsize: 1024 * 1024 * 5,
rotationFormat: false,
zippedArchive: true,
maxFiles: 10,
prettyPrint: true,
label: '',
timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS'),
eol: os.EOL,
tailable: true,
depth: null,
showLevel: true,
maxRetries: 1
}
};
let config;
if (dev) {
config = {
port: product.port,
staticDirs: product.staticDirs,
mws: product.mws
.concat([
vite ?
{
entry: require('./middlewares/vite-dev').entry,
opts: {}
}
:
{
entry: require('./middlewares/webpack-dev').entry,
opts: {}
}
])
,
logger: product.logger
}
config.logger.filename = path.join(__dirname, 'log', 'development.txt');
} else {
config = product;
}
module.exports = config;//区分开发和发布