Ignore linting healthcheck & exclue in rate-limiting

This commit is contained in:
Reginald Bondoc
2022-12-12 19:11:44 +01:00
parent 1ea75eb840
commit bcd18ab0af
5 changed files with 29 additions and 26 deletions
+3
View File
@@ -0,0 +1,3 @@
node_modules
built
healthcheck.js
+1 -4
View File
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
/* eslint-disable no-undef */
const http = require('http'); const http = require('http');
const PORT = process.env.PORT || 4000; const PORT = process.env.PORT || 4000;
const options = { const options = {
@@ -20,7 +17,7 @@ const healthCheck = http.request(options, (res) => {
}); });
healthCheck.on('error', function (err) { healthCheck.on('error', function (err) {
console.error(err); console.error(`HEALTH CHECK ERROR: ${err}`);
process.exit(1); process.exit(1);
}); });
+2 -1
View File
@@ -5,7 +5,8 @@ const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000, windowMs: 15 * 60 * 1000,
max: 400, max: 400,
standardHeaders: true, standardHeaders: true,
legacyHeaders: false legacyHeaders: false,
skip: (request) => request.path === '/healthcheck'
}); });
// 5 requests per hour // 5 requests per hour
+7 -2
View File
@@ -51,9 +51,10 @@ const connectWithRetry = () => {
console.log(e); console.log(e);
}, 5000); }, 5000);
}); });
return mongoose.connection;
}; };
connectWithRetry(); const dbConnection = connectWithRetry();
app.enable('trust proxy'); app.enable('trust proxy');
app.use(cookieParser()); app.use(cookieParser());
@@ -97,7 +98,11 @@ const server = http.createServer(app);
const onSignal = () => { const onSignal = () => {
console.log('Server is starting clean-up'); console.log('Server is starting clean-up');
return Promise.all([ return Promise.all([
// your clean logic, like closing database connections () => {
dbConnection.close(() => {
console.info('Database connection closed');
});
}
]); ]);
}; };
+1 -4
View File
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
/* eslint-disable no-undef */
const http = require('http'); const http = require('http');
const options = { const options = {
host: 'localhost', host: 'localhost',
@@ -19,7 +16,7 @@ const healthCheck = http.request(options, (res) => {
}); });
healthCheck.on('error', function (err) { healthCheck.on('error', function (err) {
console.error(err); console.error(`HEALTH CHECK ERROR: ${err}`);
process.exit(1); process.exit(1);
}); });