mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-06-16 03:05:19 -04:00
make rate-limiting and auto-restart optional via flag and modify readme
This commit is contained in:
parent
f12872bf5c
commit
57851902f9
6 changed files with 101 additions and 35 deletions
66
index.js
66
index.js
|
@ -1,7 +1,7 @@
|
|||
var process = require('process')
|
||||
var crypto = require('crypto')
|
||||
var {spawn} = require('child_process')
|
||||
var net = require('net')
|
||||
const process = require('process')
|
||||
const crypto = require('crypto')
|
||||
const {spawn} = require('child_process')
|
||||
const net = require('net')
|
||||
|
||||
// Handle SIGINT
|
||||
process.on('SIGINT', () => {
|
||||
|
@ -29,41 +29,45 @@ process.on('unhandledRejection', (reason, promise) => {
|
|||
console.log(reason)
|
||||
})
|
||||
|
||||
process.on(
|
||||
'uncaughtException',
|
||||
() => {
|
||||
process.once(
|
||||
'exit',
|
||||
() => spawn(
|
||||
process.argv.shift(),
|
||||
process.argv,
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
detached: true,
|
||||
stdio: 'inherit'
|
||||
}
|
||||
)
|
||||
);
|
||||
process.exit();
|
||||
}
|
||||
);
|
||||
if (process.argv.includes('--auto-restart')) {
|
||||
process.on(
|
||||
'uncaughtException',
|
||||
() => {
|
||||
process.once(
|
||||
'exit',
|
||||
() => spawn(
|
||||
process.argv.shift(),
|
||||
process.argv,
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
detached: true,
|
||||
stdio: 'inherit'
|
||||
}
|
||||
)
|
||||
);
|
||||
process.exit();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const express = require('express');
|
||||
const RateLimit = require('express-rate-limit');
|
||||
const http = require('http');
|
||||
|
||||
const limiter = RateLimit({
|
||||
windowMs: 5 * 60 * 1000, // 5 minutes
|
||||
max: 1000, // Limit each IP to 100 requests per `window` (here, per 5 minutes)
|
||||
message: 'Too many requests from this IP Address, please try again after 5 minutes.',
|
||||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
||||
})
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
app.use(limiter);
|
||||
if (process.argv.includes('--rate-limit')) {
|
||||
const limiter = RateLimit({
|
||||
windowMs: 5 * 60 * 1000, // 5 minutes
|
||||
max: 1000, // Limit each IP to 100 requests per `window` (here, per 5 minutes)
|
||||
message: 'Too many requests from this IP Address, please try again after 5 minutes.',
|
||||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
|
||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
||||
})
|
||||
|
||||
app.use(limiter);
|
||||
}
|
||||
|
||||
app.use(express.static('public'));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue