limiter from config

This commit is contained in:
me 2025-03-15 12:24:31 +02:00
parent c571312917
commit 0e6ceff71f
5 changed files with 12 additions and 11 deletions

View File

@ -2,6 +2,10 @@
"domain": "localhost", "domain": "localhost",
"port": 8080, "port": 8080,
"db_path": "./ucs.db", "db_path": "./ucs.db",
"limits_per_second": {
"get": 500,
"post": 20
},
"sites": { "sites": {
"localhost": { "localhost": {
"info": { "info": {
@ -9,11 +13,7 @@
"url": "localhost", "url": "localhost",
"comment_token": "שלום" "comment_token": "שלום"
}, },
"cors": ["localhost"], "cors": ["http://localhost"],
"limits_per_second": {
"get": 500,
"post": 20
},
"max_lengths": { "max_lengths": {
"user": 20, "user": 20,
"website": 100, "website": 100,

View File

@ -13,7 +13,7 @@ router.use(express.json());
// POST // POST
router.post('/:site/*', utils.limiter(20), (req, res) => { router.post('/:site/*', utils.post_limiter, (req, res) => {
const site_url = req.params.site; const site_url = req.params.site;
const path = req.params[0]; const path = req.params[0];
@ -48,7 +48,7 @@ router.post('/:site/*', utils.limiter(20), (req, res) => {
// GET // GET
router.get('/:site/*', utils.limiter(500), (req, res) => { router.get('/:site/*', utils.get_limiter, (req, res) => {
const site = req.params.site; const site = req.params.site;
const path = req.params[0]; const path = req.params[0];
const comments = db.pageComments(site, path); const comments = db.pageComments(site, path);

View File

@ -14,7 +14,7 @@ router.use(express.json());
const domain = utils.domain; const domain = utils.domain;
router.get('/:site', utils.limiter(500), (req, res) => { router.get('/:site', utils.get_limiter, (req, res) => {
const site = req.params.site; const site = req.params.site;
var feed = new Feed({ var feed = new Feed({
@ -44,7 +44,7 @@ router.get('/:site', utils.limiter(500), (req, res) => {
res.send(xml); res.send(xml);
}); });
router.get('/:site/*', utils.limiter(500), (req, res) => { router.get('/:site/*', utils.get_limiter, (req, res) => {
const site = req.params.site; const site = req.params.site;
const path = req.params[0]; const path = req.params[0];

View File

@ -10,7 +10,7 @@ import utils from './utils.mjs';
// server // server
app.use(utils.limiter(500)); app.use(utils.get_limiter);
app.use(express.static(path.join(path.dirname(fileURLToPath(import.meta.url)), "../public"))); app.use(express.static(path.join(path.dirname(fileURLToPath(import.meta.url)), "../public")));

View File

@ -43,5 +43,6 @@ export default {
db_path, db_path,
cors, cors,
escapeHtml, escapeHtml,
limiter get_limiter: limiter(config.config.limits_per_second.get),
post_limiter: limiter(config.config.limits_per_second.post),
}; };