mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Ignore linting healthcheck & exclue in rate-limiting
This commit is contained in:
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
built
|
||||||
|
healthcheck.js
|
||||||
@@ -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,34 +2,35 @@ import rateLimit from 'express-rate-limit';
|
|||||||
|
|
||||||
// 300 requests per 15 minutes
|
// 300 requests per 15 minutes
|
||||||
const apiLimiter = rateLimit({
|
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
|
||||||
const signupLimiter = rateLimit({
|
const signupLimiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000,
|
windowMs: 60 * 60 * 1000,
|
||||||
max: 10,
|
max: 10,
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false
|
legacyHeaders: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// 10 requests per hour
|
// 10 requests per hour
|
||||||
const loginLimiter = rateLimit({
|
const loginLimiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000,
|
windowMs: 60 * 60 * 1000,
|
||||||
max: 20,
|
max: 20,
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false
|
legacyHeaders: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// 5 requests per hour
|
// 5 requests per hour
|
||||||
const passwordLimiter = rateLimit({
|
const passwordLimiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000,
|
windowMs: 60 * 60 * 1000,
|
||||||
max: 10,
|
max: 10,
|
||||||
standardHeaders: true,
|
standardHeaders: true,
|
||||||
legacyHeaders: false
|
legacyHeaders: false
|
||||||
});
|
});
|
||||||
|
|
||||||
export { apiLimiter, signupLimiter, loginLimiter, passwordLimiter };
|
export { apiLimiter, signupLimiter, loginLimiter, passwordLimiter };
|
||||||
|
|||||||
@@ -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,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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user