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.

103 lines
2.4 KiB

1 year ago
/**
* 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');
1 year ago
1 year ago
12 months ago
const flags = args.parse(process.argv);
1 year ago
const FS_UNIAPP_API = process.env.FS_UNIAPP_API || flags.apiUrl;
1 year ago
const weatherUrl = process.env.ANXINCLOUD_WEATHERAPP_API || "https://weatherssj.anxinyun.cn/weatherApp/weather/getImmeData"
1 year ago
1 year ago
if (
12 months ago
!FS_UNIAPP_API
1 year ago
) {
console.log('缺少启动参数,异常退出');
args.showHelp();
process.exit(-1);
1 year ago
}
const product = {
1 year ago
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: {
12 months ago
1 year ago
}
}, {
entry: require('./middlewares/attachment').entry,
opts: {
maxSize: 104857600, // 100M
uploadPath: 'other'
}
}, {
entry: require('./routes').entry,
opts: {
1 year ago
weatherUrl,
1 year ago
}
}, {
entry: require('./client').entry,// 静态信息
opts: {
12 months ago
1 year ago
}
}],
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
}
1 year ago
};
let config;
if (dev) {
1 year ago
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');
1 year ago
} else {
1 year ago
config = product;
1 year ago
}
module.exports = config;//区分开发和发布