2020-12-21 11:26:24 +00:00
|
|
|
process.on('exit', () => {
|
2021-07-08 19:33:17 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2021-01-26 14:03:42 +00:00
|
|
|
console.log('Shutting Shutdown');
|
2020-12-21 11:26:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
process.on('unhandledRejection', err => {
|
2021-07-08 19:33:17 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2021-01-26 14:03:42 +00:00
|
|
|
console.error('Unhandled rejection in process occurred');
|
2021-07-08 19:33:17 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2020-12-21 11:26:24 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('uncaughtException', err => {
|
2021-07-08 19:33:17 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2021-01-26 14:03:42 +00:00
|
|
|
console.error('Uncaught exception in process occurred');
|
2021-07-08 19:33:17 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2020-12-21 11:26:24 +00:00
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
|
2021-01-26 14:03:42 +00:00
|
|
|
const express = require('express');
|
|
|
|
const app = express();
|
|
|
|
const path = require('path');
|
|
|
|
const version = require('./api/version');
|
|
|
|
const cors = require('cors');
|
|
|
|
|
2020-12-21 09:45:03 +00:00
|
|
|
app.use(cors());
|
|
|
|
|
|
|
|
app.use(function(req, res, next) {
|
|
|
|
if (typeof req.body === 'string') {
|
|
|
|
req.body = JSON.parse(req.body);
|
|
|
|
}
|
|
|
|
res.header('Access-Control-Allow-Credentials', true);
|
|
|
|
res.header('Access-Control-Allow-Origin', req.headers.origin);
|
|
|
|
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
|
|
|
res.header(
|
|
|
|
'Access-Control-Allow-Headers',
|
|
|
|
'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept,Authorization'
|
|
|
|
);
|
|
|
|
if (req.get('host').includes('cluster.local')) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
2021-06-29 19:18:32 +00:00
|
|
|
return next();
|
2020-12-21 09:45:03 +00:00
|
|
|
});
|
2020-03-22 11:39:12 +00:00
|
|
|
|
|
|
|
// set the server port
|
|
|
|
app.set('port', process.env.PORT || 3423);
|
|
|
|
|
|
|
|
// set the view engine to ejs
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
|
|
|
|
//serve files in public directory
|
2020-03-22 14:22:56 +00:00
|
|
|
app.use(
|
|
|
|
['/chart', '/'],
|
|
|
|
express.static(path.join(__dirname, 'public'), { maxAge: 2592000 })
|
|
|
|
);
|
2020-03-22 11:39:12 +00:00
|
|
|
|
2020-12-21 09:45:03 +00:00
|
|
|
//Application version
|
2020-12-29 11:49:54 +00:00
|
|
|
app.get(['/chart/version', '/version'], version);
|
2020-12-21 09:45:03 +00:00
|
|
|
|
2020-03-22 11:39:12 +00:00
|
|
|
app.listen(app.get('port'), function() {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('API Reference started on PORT:' + app.get('port'));
|
|
|
|
});
|
2020-12-21 11:26:24 +00:00
|
|
|
|
|
|
|
module.exports = app;
|