49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const utils = require('./utils');
|
|
const metamgr = require('./metamgr');
|
|
const bc = require('./blockchain');
|
|
const gm = require('./gm');
|
|
const C = require('./C');
|
|
|
|
const controllers = [
|
|
'order',
|
|
'buyrecord',
|
|
'log',
|
|
'nft'
|
|
];
|
|
|
|
const app = express();
|
|
|
|
utils.registerHandler('GM', 'execCmd', async (req, rsp) => {
|
|
gm.execCmd(req, rsp);
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
throw reason;
|
|
});
|
|
|
|
utils.registerEventHandler(
|
|
C.BC_INITIALIZED_EVENT,
|
|
() => {
|
|
app.get('/webapp/index.php', async (req, rsp) => {
|
|
const c = req.query.c;
|
|
const a = req.query.a;
|
|
const handler = utils.getHandler(c, a);
|
|
if (handler) {
|
|
handler(req, rsp);
|
|
} else {
|
|
utils.rspErr(rsp, 100, 'not found');
|
|
}
|
|
});
|
|
controllers.forEach((name) => {
|
|
require('./controllers/' + name).init();
|
|
});
|
|
app.use('/static', express.static('static'));
|
|
app.listen(metamgr.getServerConf()['listen_port']);
|
|
}
|
|
);
|
|
|
|
metamgr.init();
|
|
bc.init();
|