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()
|
||||
|
||||
@@ -30,6 +30,9 @@ const keysToSplit = [Providers.key, LanguageOptions.key, QualityFilter.key, Size
|
||||
const keysToUppercase = [SizeFilter.key];
|
||||
|
||||
export function parseConfiguration(configuration) {
|
||||
if (!configuration) {
|
||||
return undefined;
|
||||
}
|
||||
if (PreConfigurations[configuration]) {
|
||||
return PreConfigurations[configuration].config;
|
||||
}
|
||||
|
||||
12
addon/package-lock.json
generated
12
addon/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "stremio-torrentio",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "stremio-torrentio",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@putdotio/api-client": "^8.32.0",
|
||||
@@ -15,6 +15,7 @@
|
||||
"bottleneck": "^2.19.5",
|
||||
"cache-manager": "^3.4.4",
|
||||
"cache-manager-mongodb": "^0.3.0",
|
||||
"cors": "^2.8.5",
|
||||
"debrid-link-api": "^1.0.1",
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"magnet-uri": "^6.2.0",
|
||||
@@ -27,6 +28,7 @@
|
||||
"prom-client": "^12.0.0",
|
||||
"real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#d1f7eaa8593b947edbfbc8a92a176448b48ef445",
|
||||
"request-ip": "^3.3.0",
|
||||
"router": "^1.3.8",
|
||||
"sequelize": "^6.31.1",
|
||||
"stremio-addon-sdk": "^1.6.10",
|
||||
"swagger-stats": "^0.99.7",
|
||||
@@ -1786,9 +1788,9 @@
|
||||
"integrity": "sha512-XgmCoxKWkDofwH8WddD0w85ZfqYz+ZHlr5yo+3YUCfycWawU56T5ckWXsScsj5B8tqUcIG67DxXByo3VUgiAdA=="
|
||||
},
|
||||
"node_modules/router": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/router/-/router-1.3.4.tgz",
|
||||
"integrity": "sha512-a5uZFwgKExBZzh4U5jujU05DkImy9/ub8omiU7RlZlNnSF07tjvNJTOgHdZOjKDeUZqlkpz8CjDoz5SY3kimOA==",
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/router/-/router-1.3.8.tgz",
|
||||
"integrity": "sha512-461UFH44NtSfIlS83PUg2N7OZo86BC/kB3dY77gJdsODsBhhw7+2uE0tzTINxrY9CahCUVk1VhpWCA5i1yoIEg==",
|
||||
"dependencies": {
|
||||
"array-flatten": "3.0.0",
|
||||
"debug": "2.6.9",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "stremio-torrentio",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
"exports": "./index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
@@ -15,6 +15,7 @@
|
||||
"bottleneck": "^2.19.5",
|
||||
"cache-manager": "^3.4.4",
|
||||
"cache-manager-mongodb": "^0.3.0",
|
||||
"cors": "^2.8.5",
|
||||
"debrid-link-api": "^1.0.1",
|
||||
"express-rate-limit": "^6.7.0",
|
||||
"magnet-uri": "^6.2.0",
|
||||
@@ -27,6 +28,7 @@
|
||||
"prom-client": "^12.0.0",
|
||||
"real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#d1f7eaa8593b947edbfbc8a92a176448b48ef445",
|
||||
"request-ip": "^3.3.0",
|
||||
"router": "^1.3.8",
|
||||
"sequelize": "^6.31.1",
|
||||
"stremio-addon-sdk": "^1.6.10",
|
||||
"swagger-stats": "^0.99.7",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import getRouter from 'stremio-addon-sdk/src/getRouter.js';
|
||||
import Router from 'router';
|
||||
import cors from 'cors';
|
||||
import rateLimit from "express-rate-limit";
|
||||
import requestIp from 'request-ip';
|
||||
import userAgentParser from 'ua-parser-js';
|
||||
import addonInterface from './addon.js';
|
||||
@@ -8,8 +10,15 @@ import { parseConfiguration, PreConfigurations } from './lib/configuration.js';
|
||||
import landingTemplate from './lib/landingTemplate.js';
|
||||
import * as moch from './moch/moch.js';
|
||||
|
||||
const router = getRouter({ ...addonInterface, manifest: manifest() });
|
||||
const router = new Router();
|
||||
const limiter = rateLimit({
|
||||
windowMs: 60 * 60 * 1000, // 1 hour
|
||||
max: 300, // limit each IP to 300 requests per windowMs
|
||||
headers: false,
|
||||
keyGenerator: (req) => requestIp.getClientIp(req)
|
||||
})
|
||||
|
||||
router.use(cors())
|
||||
router.get('/', (_, res) => {
|
||||
res.redirect('/configure')
|
||||
res.end();
|
||||
@@ -34,7 +43,7 @@ router.get('/:configuration?/manifest.json', (req, res) => {
|
||||
res.end(manifestBuf)
|
||||
});
|
||||
|
||||
router.get('/:configuration/:resource/:type/:id/:extra?.json', (req, res, next) => {
|
||||
router.get('/:configuration?/:resource/:type/:id/:extra?.json', limiter, (req, res, next) => {
|
||||
const { configuration, resource, type, id } = req.params;
|
||||
const extra = req.params.extra ? qs.parse(req.url.split('/').pop().slice(0, -5)) : {}
|
||||
const ip = requestIp.getClientIp(req);
|
||||
|
||||
Reference in New Issue
Block a user