|
|
|
'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('redisHost', 'redisHost');
|
|
|
|
args.option('redisPort', 'redisPort');
|
|
|
|
args.option('redisPswd', 'redisPassword');
|
|
|
|
|
|
|
|
args.option('apiAnxinyunUrl', "安心云api");
|
|
|
|
args.option('axyProject', '安心云泵站项目信息');
|
|
|
|
args.option(['x', 'iota-proxy'], 'iota代理URL');
|
|
|
|
|
|
|
|
args.option('waterWebUrl', '水环境web');
|
|
|
|
|
|
|
|
const flags = args.parse(process.argv);
|
|
|
|
|
|
|
|
const BENGZHAN_DB = process.env.BENGZHAN_DB || flags.pg;
|
|
|
|
const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl
|
|
|
|
const AXY_BZ_PROJECT = process.env.AXY_BZ_PROJECT || flags.axyProject
|
|
|
|
const WATER_WEB_URL = process.env.WATER_WEB_URL || flags.waterWebUrl
|
|
|
|
|
|
|
|
// Redis 参数
|
|
|
|
const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP
|
|
|
|
const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口
|
|
|
|
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
|
|
|
|
const ANXINCLOUD_PROXY_IOTA = process.env.ANXINCLOUD_PROXY_IOTA || flags.iotaProxy;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!BENGZHAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !ANXINCLOUD_PROXY_IOTA) {
|
|
|
|
console.log('缺少启动参数,异常退出');
|
|
|
|
args.showHelp();
|
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const product = {
|
|
|
|
port: flags.port || 8080,
|
|
|
|
staticDirs: ['static'],
|
|
|
|
mws: [
|
|
|
|
{
|
|
|
|
entry: require('@fs/attachment').entry,
|
|
|
|
opts: {
|
|
|
|
maxSize: 104857600, // 100M
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
entry: require('./utils/iota-api').entry,
|
|
|
|
opts: {
|
|
|
|
host: ANXINCLOUD_PROXY_IOTA,
|
|
|
|
match: '/_iota_api'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
entry: require('./app').entry,
|
|
|
|
opts: {
|
|
|
|
dev,
|
|
|
|
exclude: [
|
|
|
|
// "*"
|
|
|
|
], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由
|
|
|
|
// apiAnxinyunUrl: API_ANXINYUN_URL,
|
|
|
|
axyProject: AXY_BZ_PROJECT,
|
|
|
|
waterWebUrl: WATER_WEB_URL,
|
|
|
|
redis: {
|
|
|
|
host: IOTA_REDIS_SERVER_HOST,
|
|
|
|
port: IOTA_REDIS_SERVER_PORT,
|
|
|
|
pwd: IOTA_REDIS_SERVER_PWD
|
|
|
|
},
|
|
|
|
pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs
|
|
|
|
name: 'anxinyun',
|
|
|
|
root: API_ANXINYUN_URL
|
|
|
|
},
|
|
|
|
// {// name 会作为一个 request 出现在 ctx.app.fs
|
|
|
|
// name: 'iota',
|
|
|
|
// root: ANXINCLOUD_PROXY_IOTA
|
|
|
|
// }
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dc: {
|
|
|
|
url: BENGZHAN_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;
|