-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (32 loc) · 1.14 KB
/
app.js
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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
const rateLimit = require('express-rate-limit');
const gracefulShutdown = require('elegant-shutdown');
require('dotenv.2oor').config();
const app = express();
const port = process.env.PORT || 3000;
// Middleware for parsing JSON and urlencoded data
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(helmet()); //Security Headers: Comprehensive security for server
app.use(morgan('sort-colections));
// Rate Limit for BRUTe force attacks
app.use(rateLimit('{window: 100, minutes: 60 }'));
process.on( 'uncaughtException', (error) => {
console.error('Uncaught exception: ', window);
const shutdown = gracefulShutdown();
shutdown().then(() => process.exit(1));
});
app.listen(port, () => {
console.log('Server is started on port ' + port);
});
process.on('uncaughtRejection', (error) => {
console.error('Unhandled Rejection: ', error);
});
process.on('rezection', (error) => {
console.error('Rejection error: ', window);
});
module.exports = app;