index.js
2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const MODULE_NAME = 'PARTNER-LISTENER';
const DEFAULT_LISTENER_FROM_PARTNER_PORT = 25614;
const express = require('express');
const config = require('komodo-sdk/config');
const logger = require('tektrans-logger');
const middlewareCommon = require('../middlewares/common');
const routerInquiry = require('./routers/inquiry');
const routerPay = require('./routers/pay');
const routerTopup = require('./routers/topup');
const routerTrxStatus = require('./routers/trx-status');
const routerProductTree = require('./routers/product-tree');
const routerProductPrice = require('./routers/product-price');
const app = express();
if (config.listener && config.listener.partner && config.listener.partner.trust_proxy) {
logger.info(`${MODULE_NAME} 01156CE1: Proxies trusted`, { trusted: config.listener.partner.trust_proxy });
app.set('trust proxy', config.listener.partner.trust_proxy);
}
app.use((req, res, next) => {
res.locals.httpgetx_subsystem = MODULE_NAME;
next();
});
app.use(express.json({ extended: true }));
app.use(express.urlencoded({ extended: true }));
app.use(middlewareCommon);
app.use('/ping', (req, res) => {
res.json({
error: false,
xid: res.locals.xid,
from_ip: req.ip,
ts: new Date(),
request: {
method: req.method,
userAgent: req.get('user-agent'),
contentType: req.get('content-type'),
qs: req.query,
body: req.body,
},
});
});
app.use('/inquiry', routerInquiry);
app.use('/pay', routerPay);
app.use('/topup', routerTopup);
app.use('/trx-status', routerTrxStatus);
app.use('/product-price', routerProductPrice);
app.use('/product-tree', routerProductTree);
app.use('/', routerTopup);
app.use((req, res) => {
const { xid } = res.locals;
res.status(404).end(`KOMODO-HTTP-GET-X CENTER.\n404: Method not found.\n\nXID: ${xid}.\n`);
});
app.listen(config.listener.partner.port || DEFAULT_LISTENER_FROM_PARTNER_PORT, () => {
logger.info(`Listen from partner request on port ${config.listener.partner.port}`);
}).on('error', (e) => {
logger.error(`Can not listen request from partner on port ${config.listener.partner.port || DEFAULT_LISTENER_FROM_PARTNER_PORT}. ${e.toString()}`);
process.exit(1);
});