mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
move rate limiting directly to handler
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import express from 'express';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import swStats from 'swagger-stats';
|
||||
import requestIp from 'request-ip';
|
||||
import serverless from './serverless.js';
|
||||
import { manifest } from './lib/manifest.js';
|
||||
import { initBestTrackers } from './lib/magnetHelper.js';
|
||||
@@ -11,7 +9,7 @@ app.enable('trust proxy');
|
||||
app.use(swStats.getMiddleware({
|
||||
name: manifest().name,
|
||||
version: manifest().version,
|
||||
timelineBucketDuration: 10 * 60 * 1000,
|
||||
timelineBucketDuration: 60 * 60 * 1000,
|
||||
apdexThreshold: 100,
|
||||
authentication: true,
|
||||
onAuthenticate: (req, username, password) => {
|
||||
@@ -20,12 +18,6 @@ app.use(swStats.getMiddleware({
|
||||
},
|
||||
}))
|
||||
app.use(express.static('static', { maxAge: '1y' }));
|
||||
app.use(/^\/.*stream\/.+/, rateLimit({
|
||||
windowMs: 60 * 60 * 1000, // 1 hours
|
||||
max: 300, // limit each IP to 300 requests per windowMs
|
||||
headers: false,
|
||||
keyGenerator: (req) => requestIp.getClientIp(req)
|
||||
}));
|
||||
app.use((req, res, next) => serverless(req, res, next));
|
||||
app.listen(process.env.PORT || 7000, () => {
|
||||
initBestTrackers()
|
||||
|
||||
Reference in New Issue
Block a user