'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(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地址(必填), 该服务器提供文件上传Web服务'); args.option('redisHost', 'redisHost'); args.option('redisPort', 'redisPort'); args.option('redisPswd', 'redisPassword'); args.option('apiEmisUrl', '企业管理 api'); // 七牛云存储参数 args.option('qnak', 'qiniuAccessKey'); args.option('qnsk', 'qiniuSecretKey'); args.option('qnbkt', 'qiniuBucket'); args.option('qndmn', 'qiniuDomain'); // clickHouse args.option('clickHouseUrl', 'clickHouse Url'); args.option('clickHousePort', 'clickHouse Port'); args.option('clickHousePepEmis', 'clickHouse 项企数据库名称'); args.option('clickHouseCamworkflow', 'clickHouse 工作流数据库名称'); args.option('clickHouseHr', 'clickHouse 人资数据库名称'); const flags = args.parse(process.argv); const HR_DB = process.env.HR_DB || flags.pg; const LOCAL_SVR_ORIGIN = process.env.LOCAL_SVR_ORIGIN || flags.fileHost; // 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 密码 // 企业管理 api const API_EMIS_URL = process.env.API_EMIS_URL || flags.apiEmisUrl; // 七牛云存储参数 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; // 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_PEP_EMIS = process.env.CLICKHOUST_PEP_EMIS || flags.clickHousePepEmis const CLICKHOUST_CAM_WORKFLOW = process.env.CLICKHOUST_CAM_WORKFLOW || flags.clickHouseCamworkflow const CLICKHOUST_HR = process.env.CLICKHOUST_HR || flags.clickHouseHr // timor 节假日查询 const API_TIMOR_URL = 'http://timor.tech/api/' if ( !HR_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !API_EMIS_URL || !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK || !CLICKHOUST_URL || !CLICKHOUST_PORT || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_CAM_WORKFLOW || !CLICKHOUST_HR ) { 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: 209715200, // 200M } }, { entry: require('./app').entry, opts: { dev, exclude: [ ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 workFlow: { processState: [ 'WAIT', //保存待发 'ACTIVE', // 正在运行中 'SUSPENDED', // 流程暂停 'COMPLETED', //流程正常结束 'EXTERNALLY_TERMINATED', // 手动结束流程 'INTERNALLY_TERMINATED' //流程异常结束 ] }, qiniu: { domain: QINIU_DOMAIN_QNDMN_RESOURCE, bucket: QINIU_BUCKET_RESOURCE, accessKey: QINIU_AK, secretKey: QINIU_SK }, redis: { host: IOTA_REDIS_SERVER_HOST, port: IOTA_REDIS_SERVER_PORT, pwd: IOTA_REDIS_SERVER_PWD }, sms: { ///阿里云-安心云 accessKey: 'LTAI5tAFdjz7j38aNF2C9Qe8', accessSecret: '1trYkmiqfBtvZL6BxkNH2uQcQQPs0S' }, email: { enabled: true, host: 'smtp.exmail.qq.com', port: 465, sender: { name: '人资服务', address: 'fsiot@free-sun.com.cn', password: 'Fs2689' } }, timorApiUrl: API_TIMOR_URL, pssaRequest: [{ name: 'emisRequest', root: API_EMIS_URL },], clickHouse: { url: CLICKHOUST_URL, port: CLICKHOUST_PORT, user: CLICKHOUST_USER, password: CLICKHOUST_PASSWORD, db: [ { name: 'pepEmis', db: CLICKHOUST_PEP_EMIS }, { name: 'camWorkflow', db: CLICKHOUST_CAM_WORKFLOW }, { name: 'hr', db: CLICKHOUST_HR } ] } } } ], dc: { url: HR_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;