index.js
830 Bytes
const express = require('express');
const morgan = require('morgan');
const rfs = require('rotating-file-stream');
const config = require('komodo-sdk/config');
const logger = require('tektrans-logger');
const handlerOnReceived = require('./handler/on-received');
const app = express();
const accessLogStream = rfs.createStream('apiserver.access_log', {
interval: '1d',
path: './logs',
});
app.use(morgan('combined', { stream: accessLogStream }));
app.get('/ping', (req, res) => { res.end('PONG'); });
app.get('/service', handlerOnReceived);
const listenPort = config.apiserver.port;
app.listen(listenPort, () => {
logger.info(`APISERVER: Listen on port ${listenPort}`);
}).on('error', (err) => {
logger.warn(`APISERVER: Can not listen on port ${listenPort}`, { err: err.message });
process.exit(1);
});