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.
251 lines
7.9 KiB
251 lines
7.9 KiB
'use strict';
|
|
/*jslint node:true*/
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const moment = require('moment');
|
|
const args = require('args');
|
|
|
|
const dev = process.env.NODE_ENV == 'development';
|
|
|
|
// 启动参数
|
|
args.option(['p', 'port'], '启动端口');
|
|
args.option(['g', 'pg'], 'postgre 服务 URL');
|
|
|
|
// 七牛云存储参数
|
|
args.option('qnak', 'qiniuAccessKey');
|
|
args.option('qnsk', 'qiniuSecretKey');
|
|
args.option('qnbkt', 'qiniuBucket');
|
|
args.option('qndmn', 'qiniuDomain');
|
|
|
|
// 微信小程序参数
|
|
args.option('wxDomain', '微信API Domain');
|
|
args.option('wxAppId', '微信小程序appid');
|
|
args.option('wxAppSecret', '微信小程序AppSecret');
|
|
|
|
//以太代理
|
|
args.option('iotaProxy', '以太代理')
|
|
|
|
//设备升级
|
|
args.option('apiCrawUrl', '设备升级')
|
|
|
|
|
|
args.option('apiAnxinyunUrl', "安心云api");
|
|
args.option('axyProject', '安心云泵站项目信息');
|
|
|
|
// clickHouse
|
|
args.option('clickHouseUrl', 'clickHouse Url');
|
|
args.option('clickHousePort', 'clickHouse Port');
|
|
args.option('clickHouseUser', 'clickHouse user');
|
|
args.option('clickHousePassword', 'clickHouse password');
|
|
// args.option('clickHouseAnxincloud', 'clickHouse 安心云数据库名称');
|
|
// args.option('clickHousePepEmis', 'clickHouse 项企数据库名称');
|
|
// args.option('clickHouseProjectManage', 'clickHouse 项目管理数据库名称');
|
|
// args.option('clickHouseVcmp', 'clickHouse 视频平台数据库名称');
|
|
args.option('clickHouseDataAlarm', 'clickHouse 视频平台数据告警库名称');
|
|
// args.option('clickHouseDataAlarmLocal', 'clickHouse 本地化告警相关数据');
|
|
args.option('clickHouseIot', 'clickHouse IOT平台设备信息库名称');
|
|
// args.option('clickHouseCamworkflow', 'clickHouse 工作流数据库名称');
|
|
|
|
const flags = args.parse(process.argv);
|
|
|
|
const XUNJIAN_DB = process.env.XUNJIAN_DB || flags.pg;
|
|
|
|
// 以太代理
|
|
const IOT_PROXY = process.env.IOT_PROXY || flags.iotaProxy;
|
|
|
|
// 七牛云存储参数
|
|
const QINIU_DOMAIN_QNDMN_RESOURCE = process.env.ANXINCLOUD_QINIU_DOMAIN_QNDMN_RESOURCE || flags.qndmn;
|
|
const QINIU_BUCKET_RESOURCE = process.env.ANXINCLOUD_QINIU_BUCKET_RESOURCE || flags.qnbkt;
|
|
const QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak;
|
|
const QINIU_SK = process.env.ANXINCLOUD_QINIU_SECRETKEY || flags.qnsk;
|
|
|
|
// 微信小程序参数
|
|
const WX_DOMAIN = process.env.WX_DOMAIN || flags.wxDomain;
|
|
const WX_APP_ID = process.env.WX_APP_ID || flags.wxAppId;
|
|
const WX_APP_SECRET = process.env.WX_APP_SECRET || flags.wxAppSecret;
|
|
//报表
|
|
const API_REPOR_GENERATE_URL = process.env.API_REPOR_GENERATE_URL || 'http://10.8.30.95:31825'
|
|
//安心云接口
|
|
const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl
|
|
const AXY_BZ_PROJECT = process.env.AXY_BZ_PROJECT || flags.axyProject
|
|
//设备升级
|
|
const API_CRAW_URL = process.env.API_CRAW_URL || flags.apiCrawUrl;
|
|
//clickHouse
|
|
const CLICKHOUST_URL = process.env.CLICKHOUST_URL || flags.clickHouseUrl
|
|
const CLICKHOUST_PORT = process.env.CLICKHOUST_PORT || flags.clickHousePort
|
|
const CLICKHOUST_USER = process.env.CLICKHOUST_USER || flags.clickHouseUser
|
|
// const CLICKHOUST_PASSWORD = process.env.CLICKHOUST_PASSWORD || flags.clickHousePassword
|
|
const CLICKHOUST_DATA_ALARM = process.env.CLICKHOUST_DATA_ALARM || flags.clickHouseDataAlarm
|
|
const CLICKHOUST_IOT = process.env.CLICKHOUST_IOT || flags.clickHouseIot
|
|
|
|
|
|
if (!XUNJIAN_DB || !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK || !WX_DOMAIN || !WX_APP_ID || !WX_APP_SECRET || !API_ANXINYUN_URL|| !AXY_BZ_PROJECT
|
|
||!IOT_PROXY||!API_CRAW_URL||!CLICKHOUST_URL||!CLICKHOUST_PORT||!CLICKHOUST_USER||!CLICKHOUST_IOT
|
|
//!CLICKHOUST_PASSWORD||
|
|
) {
|
|
console.log('缺少启动参数,异常退出');
|
|
args.showHelp();
|
|
process.exit(-1);
|
|
}
|
|
|
|
const product = {
|
|
port: flags.port || 8080,
|
|
staticDirs: ['static'],
|
|
mws: [
|
|
{
|
|
entry: require('@fs/attachment').entry,
|
|
opts: {
|
|
qiniu: {
|
|
domain: QINIU_DOMAIN_QNDMN_RESOURCE,
|
|
bucket: QINIU_BUCKET_RESOURCE,
|
|
accessKey: QINIU_AK,
|
|
secretKey: QINIU_SK
|
|
},
|
|
maxSize: 104857600, // 100M
|
|
}
|
|
}, {
|
|
entry: require('./app/lib/middlewares/attachment').entry,
|
|
opts: {
|
|
qiniu: {
|
|
accessKey: QINIU_AK,
|
|
secretKey: QINIU_SK,
|
|
bucket: QINIU_BUCKET_RESOURCE,
|
|
domain: QINIU_DOMAIN_QNDMN_RESOURCE
|
|
},
|
|
maxSize: 104857600, // 100M
|
|
// uploadPath: 'other'
|
|
}
|
|
}, {
|
|
entry: require('./app').entry,
|
|
opts: {
|
|
dev,
|
|
exclude: [
|
|
// "*"
|
|
], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由
|
|
axyProject: AXY_BZ_PROJECT,
|
|
qiniu: {
|
|
domain: QINIU_DOMAIN_QNDMN_RESOURCE,
|
|
bucket: QINIU_BUCKET_RESOURCE,
|
|
accessKey: QINIU_AK,
|
|
secretKey: QINIU_SK
|
|
},
|
|
sms: {
|
|
///阿里云-安心云
|
|
accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8',
|
|
accessSecret: '1trYkmiqfBtvZL6BxkNH2uQcQQPs0S'
|
|
},
|
|
pssaRequest:[
|
|
{ name: 'reportGenerate',
|
|
root: API_REPOR_GENERATE_URL,
|
|
dataWord: 'text'
|
|
}, {
|
|
name: 'iotRequest',
|
|
root: IOT_PROXY + '/_iota_api',
|
|
dataWord: 'text'
|
|
}, {
|
|
name: 'iotInvoke',
|
|
root: IOT_PROXY + '/_iota_api',
|
|
},
|
|
|
|
{
|
|
name: 'anxinyun',
|
|
root: API_ANXINYUN_URL
|
|
},
|
|
{
|
|
name: 'craw',
|
|
root: API_CRAW_URL,
|
|
dataWord: 'text'
|
|
},
|
|
],
|
|
clickHouse: {
|
|
url: CLICKHOUST_URL,
|
|
port: CLICKHOUST_PORT,
|
|
user: CLICKHOUST_USER,
|
|
// password: CLICKHOUST_PASSWORD,
|
|
db: [
|
|
{
|
|
name: 'dataAlarm',
|
|
db: CLICKHOUST_DATA_ALARM
|
|
},
|
|
{
|
|
name: 'iot',
|
|
db: CLICKHOUST_IOT
|
|
},
|
|
]
|
|
},
|
|
|
|
email: {
|
|
enabled: true,
|
|
host: 'smtp.exmail.qq.com',
|
|
port: 465,
|
|
sender: {
|
|
name: '运维服务',
|
|
address: 'fsiot@free-sun.com.cn',
|
|
password: 'Fs2689'
|
|
}
|
|
},
|
|
wx: {
|
|
domain: WX_DOMAIN,
|
|
appId: WX_APP_ID,
|
|
appSecret: WX_APP_SECRET
|
|
}
|
|
}
|
|
}
|
|
],
|
|
dc: {
|
|
url: XUNJIAN_DB,
|
|
opts: {
|
|
pool: {
|
|
max: 80,
|
|
min: 10,
|
|
idle: 10000
|
|
},
|
|
define: {
|
|
freezeTableName: true, // 固定表名
|
|
timestamps: false // 不含列 "createAt"/"updateAt"/"DeleteAt"
|
|
},
|
|
timezone: '+08:00',
|
|
logging: false
|
|
},
|
|
models: [require('./app').models]
|
|
},
|
|
logger: {
|
|
level: 'info',
|
|
json: false,
|
|
filename: path.join(__dirname, 'log', 'runtime.log'),
|
|
colorize: false,
|
|
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
|
|
}
|
|
};
|
|
|
|
const development = {
|
|
port: product.port,
|
|
staticDirs: product.staticDirs,
|
|
mws: product.mws,
|
|
dc: product.dc,
|
|
logger: product.logger
|
|
};
|
|
|
|
if (dev) {
|
|
// mws
|
|
for (let mw of development.mws) {
|
|
// if (mw.opts.exclude) mw.opts.exclude = ['*']; // 使用 ['*'] 跳过所有路由
|
|
}
|
|
// logger
|
|
development.logger.filename = path.join(__dirname, 'log', 'development.log');
|
|
development.logger.level = 'debug';
|
|
development.dc.opts.logging = console.log;
|
|
}
|
|
|
|
module.exports = dev ? development : product;
|
|
|