lndhub/index.js

57 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2021-01-04 12:49:42 +00:00
process.on('uncaughtException', function (err) {
2019-01-06 14:36:23 +00:00
console.error(err);
console.log('Node NOT Exiting...');
});
2018-12-02 22:17:02 +00:00
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
let express = require('express');
2021-06-21 11:29:13 +00:00
const helmet = require('helmet');
2018-12-02 22:17:02 +00:00
let morgan = require('morgan');
2021-01-04 12:49:42 +00:00
import { v4 as uuidv4 } from 'uuid';
2018-12-02 22:17:02 +00:00
let logger = require('./utils/logger');
2021-04-29 14:31:13 +00:00
const config = require('./config');
2018-12-02 22:17:02 +00:00
morgan.token('id', function getId(req) {
return req.id;
});
let app = express();
2019-03-21 21:45:22 +00:00
app.enable('trust proxy');
2021-06-21 11:29:13 +00:00
app.use(helmet.hsts());
app.use(helmet.hidePoweredBy());
2019-03-21 21:45:22 +00:00
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
2021-04-29 14:31:13 +00:00
max: config.rateLimit || 200,
2019-03-21 21:45:22 +00:00
});
app.use(limiter);
2018-12-02 22:17:02 +00:00
2021-01-04 12:49:42 +00:00
app.use(function (req, res, next) {
req.id = uuidv4();
2018-12-02 22:17:02 +00:00
next();
});
app.use(
morgan(
':id :remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"',
),
);
let bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json(null)); // parse application/json
2018-12-09 22:46:14 +00:00
app.use('/static', express.static('static'));
2018-12-02 22:17:02 +00:00
app.use(require('./controllers/api'));
2018-12-08 15:47:48 +00:00
app.use(require('./controllers/website'));
2018-12-02 22:17:02 +00:00
const bindHost = process.env.HOST || '0.0.0.0';
const bindPort = process.env.PORT || 3000;
let server = app.listen(bindPort, bindHost, function () {
logger.log('BOOTING UP', 'Listening on ' + bindHost + ':' + bindPort);
2018-12-02 22:17:02 +00:00
});
module.exports = server;