diff --git a/app.js b/app.js index e963451..45682c2 100644 --- a/app.js +++ b/app.js @@ -92,11 +92,50 @@ function getDbConn(name) { }); } +app.use(bodyParse.json({ limit: '50mb'})); +app.use(bodyParse.urlencoded({ limit: '50mb', extended: true})); + process.on('unhandledRejection', (reason, promise) => { console.log('Unhandled Rejection at:', promise, 'reason:', reason); throw reason; }); +app.post('/webapp/index.php', async (req, rsp) => { + const c = req.query.c; + const a = req.query.a; + const handler = handlers[a + '@' + c]; + try { + if (handler) { + const cb = handler['cb']; + const middlewares = handler['middlewares']; + if (sessionClass) { + const session = new sessionClass(req, rsp); + try { + await Promise.all(middlewares.map(async (m) => { + await m(session); + })); + await cb(session); + } finally { + await session.destory(); + } + } else { + await Promise.all(middlewares.map(async (m) => { + await m(req, rsp); + })); + await cb(req, rsp); + } + } else { + utils.rspErr(rsp, 100, 'not found'); + } + } catch (err) { + if (err instanceof error.InternalError) { + utils.rspErr(rsp, err.errCode, err.errMsg); + } else { + throw err; + } + } +}); + app.get('/webapp/index.php', async (req, rsp) => { const c = req.query.c; const a = req.query.a; @@ -165,9 +204,6 @@ registerHandler('Ops', 'selfChecking', async (req, rsp) => { } }); -app.use(bodyParse.json({ limit: '50mb'})); -app.use(bodyParse.urlencoded({ limit: '50mb', extended: true})); - exports.init = init; exports.listen = listen; exports.get = get;