index.js
1005 Bytes
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
const MODULE_NAME = 'HTTP-SERVER';
const express = require('express');
const uniqid = require('uniqid');
const logger = require('tektrans-logger');
const config = require('../config');
const matrix = require('../matrix');
const checkApikey = require('./middlewares/check-apikey');
const routerMatrix = require('./routers/matrix');
const routerUpdates = require('./routers/updates');
const routerProducts = require('./routers/products');
const app = express();
app.use((req, res, next) => {
matrix.httpServer.requestCounter += 1;
res.locals.xid = uniqid();
next();
});
app.use('/matrix', routerMatrix);
app.use('/apikey/:apikey/updates', [checkApikey], routerUpdates);
app.use('/apikey/:apikey/products', [checkApikey], routerProducts);
app.use((req, res) => {
res.status(404).json({
error: true,
message: 'Method/service not found',
});
});
const { port } = config;
app.listen(port, () => {
logger.info(`${MODULE_NAME} 35069698: Listening`, { port });
});