78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
"use strict";
|
|
const moment = require('moment');
|
|
const path = require('path')
|
|
const chalk = require('chalk')
|
|
const PNG16Convertor = require('./app/microprogram/PNG16Convertor.js');
|
|
const child_process = require('child_process');
|
|
module.exports = app => {
|
|
app.beforeStart(async () => {
|
|
// 应用会等待这个函数执行完成才启动
|
|
|
|
//初始化公共数据
|
|
let ctx = app.createAnonymousContext();
|
|
// try {
|
|
// await ctx.service.util.initData();
|
|
// } catch (error) {
|
|
// throw new Error('初始化数据失败', error);
|
|
// }
|
|
['DICOM', 'SCP_STORE'].forEach(element => {
|
|
try {
|
|
ctx.service.util.createDirectory(path.join(__dirname, `app/public/${element}`))
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
});
|
|
// child_process.exec(CMD, (error, stderr, stdout) => {
|
|
// })
|
|
|
|
// try {
|
|
// await ctx.service.util.storesPython()
|
|
// } catch (error) {
|
|
// console.error(error)
|
|
// }
|
|
|
|
|
|
moment.locale('zh-cn')
|
|
app.moment = moment;
|
|
|
|
app.log = {};
|
|
app.log.error = function (msg, ...param) {
|
|
console.log(chalk.blue.bgRed.bold(msg), ...param);
|
|
};
|
|
app.log.warning = (msg, ...param) => console.log(chalk.yellow.bold(msg), ...param);
|
|
app.log.success = (msg, ...param) => console.log(chalk.green.bold(msg), ...param);
|
|
app.log.success('项目启动成功')
|
|
try {
|
|
for (var i = 0; i < app.config.png16.num; i++) {
|
|
let spawnPNG = new PNG16Convertor(app)
|
|
app.config.png16.spawn.push(spawnPNG)
|
|
}
|
|
app.log.success('启动PNG转换进程成功')
|
|
|
|
} catch (error) {
|
|
throw new Error('启动PNG转换进程失败');
|
|
}
|
|
});
|
|
app.once("server", server => {
|
|
});
|
|
app.on("error", (err, ctx) => {
|
|
// report error
|
|
});
|
|
app.on("request", ctx => {
|
|
// log receive request
|
|
const used = Date.now() - ctx.starttime;
|
|
console.log(`request:::${ctx.method} ${ctx.url} - ${used}ms`);
|
|
});
|
|
app.on("response", ctx => {
|
|
// ctx.starttime is set by framework
|
|
const used = Date.now() - ctx.starttime;
|
|
console.log(`response:::${ctx.method} ${ctx.url} - ${used}ms`);
|
|
});
|
|
};
|
|
|
|
|
|
process.on('uncaughtException', function (err) {
|
|
err.name = "UncaughtExceptionError";
|
|
console.log('Caught exception: ' + err);
|
|
});
|