四好公路
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.
 
 
 
 

121 lines
3.7 KiB

/**
* Created by rain on 2016/1/25.
*/
'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';
dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,维护良好的开发环境,媛猿有责');
// // 启动参数
args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiUrl', '可外网访问的 webapi 的URL');
args.option(['r', 'report-node'], '报表进程地址');
args.option('qndmn', '七牛');
args.option('vcmpWebUrl', '视频平台web可访问地址');
args.option('vcmpMirrorId', '视频平台镜像服务id')
args.option('olMapArcgisHost', '江西公路地图 arcgis 查询地址')
args.option('olMapGeoDataHost', '江西公路地图 geoData 查询地址')
const flags = args.parse(process.argv);
const FS_UNIAPP_API = process.env.FS_UNIAPP_API || flags.apiUrl;
const QINIU_DOMAIN_QNDMN_RESOURCE = process.env.ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn;
const API_URL = process.env.API_URL || flags.apiUrl;
//
const VCMP_WEB_URL = process.env.VCMP_WEB_URL || flags.vcmpWebUrl;
const VCMP_MIRROR_ID = process.env.VCMP_MIRROR_ID || flags.vcmpMirrorId;
//
const OL_MAP_ARC_GIS_HOST = process.env.OL_MAP_ARC_GIS_HOST || flags.olMapArcgisHost || 'http://36.2.6.33:6080';
const OL_MAP_GEO_DATA_HOST = process.env.OL_MAP_GEO_DATA_HOST || flags.olMapGeoDataHost || 'http://36.2.6.32:8811';
if (
!FS_UNIAPP_API ||
!VCMP_WEB_URL || !VCMP_MIRROR_ID
) {
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: FS_UNIAPP_API,
match: /^\/_api\//,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: QINIU_DOMAIN_QNDMN_RESOURCE,
match: /^\/_file-server\//,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: 'https://report.amap.com',
match: /^\/_godTrans\//,
}
}, {
entry: require('./routes').entry,
opts: {
apiUrl: API_URL,
qndmn: QINIU_DOMAIN_QNDMN_RESOURCE,
vcmpWebUrl: VCMP_WEB_URL,
vcmpMirrorId: VCMP_MIRROR_ID,
staticRoot: './client',
olMapArcgisHost: OL_MAP_ARC_GIS_HOST,
olMapGeoDataHost: OL_MAP_GEO_DATA_HOST
}
}, {
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([
{
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;//区分开发和发布