Skip to content

Commit

Permalink
Ignore linting healthcheck & exclue in rate-limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldbondoc committed Dec 12, 2022
1 parent 1ea75eb commit bcd18ab
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
built
healthcheck.js
5 changes: 1 addition & 4 deletions backend/healthcheck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
/* eslint-disable no-undef */
const http = require('http');
const PORT = process.env.PORT || 4000;
const options = {
Expand All @@ -20,7 +17,7 @@ const healthCheck = http.request(options, (res) => {
});

healthCheck.on('error', function (err) {
console.error(err);
console.error(`HEALTH CHECK ERROR: ${err}`);
process.exit(1);
});

Expand Down
33 changes: 17 additions & 16 deletions backend/src/helpers/rateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@ import rateLimit from 'express-rate-limit';

// 300 requests per 15 minutes
const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 400,
standardHeaders: true,
legacyHeaders: false
windowMs: 15 * 60 * 1000,
max: 400,
standardHeaders: true,
legacyHeaders: false,
skip: (request) => request.path === '/healthcheck'
});

// 5 requests per hour
const signupLimiter = rateLimit({
windowMs: 60 * 60 * 1000,
max: 10,
standardHeaders: true,
legacyHeaders: false
windowMs: 60 * 60 * 1000,
max: 10,
standardHeaders: true,
legacyHeaders: false
});

// 10 requests per hour
const loginLimiter = rateLimit({
windowMs: 60 * 60 * 1000,
max: 20,
standardHeaders: true,
legacyHeaders: false
windowMs: 60 * 60 * 1000,
max: 20,
standardHeaders: true,
legacyHeaders: false
});

// 5 requests per hour
const passwordLimiter = rateLimit({
windowMs: 60 * 60 * 1000,
max: 10,
standardHeaders: true,
legacyHeaders: false
windowMs: 60 * 60 * 1000,
max: 10,
standardHeaders: true,
legacyHeaders: false
});

export { apiLimiter, signupLimiter, loginLimiter, passwordLimiter };
9 changes: 7 additions & 2 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const connectWithRetry = () => {
console.log(e);
}, 5000);
});
return mongoose.connection;
};

connectWithRetry();
const dbConnection = connectWithRetry();

app.enable('trust proxy');
app.use(cookieParser());
Expand Down Expand Up @@ -97,7 +98,11 @@ const server = http.createServer(app);
const onSignal = () => {
console.log('Server is starting clean-up');
return Promise.all([
// your clean logic, like closing database connections
() => {
dbConnection.close(() => {
console.info('Database connection closed');
});
}
]);
};

Expand Down
5 changes: 1 addition & 4 deletions frontend/scripts/healthcheck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
/* eslint-disable no-undef */
const http = require('http');
const options = {
host: 'localhost',
Expand All @@ -19,7 +16,7 @@ const healthCheck = http.request(options, (res) => {
});

healthCheck.on('error', function (err) {
console.error(err);
console.error(`HEALTH CHECK ERROR: ${err}`);
process.exit(1);
});

Expand Down

0 comments on commit bcd18ab

Please sign in to comment.