mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(api): also rate limit etapi docs endpoint (#6352)
This commit is contained in:
commit
86f90e6685
@ -3,12 +3,18 @@ import type { Router } from "express";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { RESOURCE_DIR } from "../services/resource_dir";
|
import { RESOURCE_DIR } from "../services/resource_dir";
|
||||||
|
import rateLimit from "express-rate-limit";
|
||||||
|
|
||||||
const specPath = path.join(RESOURCE_DIR, "etapi.openapi.yaml");
|
const specPath = path.join(RESOURCE_DIR, "etapi.openapi.yaml");
|
||||||
let spec: string | null = null;
|
let spec: string | null = null;
|
||||||
|
|
||||||
|
const limiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
|
max: 100, // limit each IP to 100 requests per windowMs
|
||||||
|
});
|
||||||
|
|
||||||
function register(router: Router) {
|
function register(router: Router) {
|
||||||
router.get("/etapi/etapi.openapi.yaml", (_, res) => {
|
router.get("/etapi/etapi.openapi.yaml", limiter, (_, res) => {
|
||||||
if (!spec) {
|
if (!spec) {
|
||||||
spec = fs.readFileSync(specPath, "utf8");
|
spec = fs.readFileSync(specPath, "utf8");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user