- aggiunto componenti per Home Template... ma ancora da provare

- sistemato catprods
- Sistemato menu
This commit is contained in:
Surya Paolo
2025-09-22 19:09:02 +02:00
parent 4a05ddee50
commit 08cf4b6d9f
31 changed files with 475 additions and 31 deletions

View File

@@ -0,0 +1,6 @@
// @ts-check
const ah = (fn) => (req, res, next) =>
Promise.resolve(fn(req, res, next)).catch((err) => next(err));
module.exports = { ah };

View File

@@ -0,0 +1,13 @@
// @ts-check
function notFound(_req, res) {
res.status(404).json({ message: 'Not Found' });
}
function errorHandler(err, _req, res, _next) {
const status = err.status || 500;
const message = err.message || 'Server Error';
if (status >= 500) console.error(err);
res.status(status).json({ message });
}
module.exports = { notFound, errorHandler };

View File

@@ -0,0 +1,21 @@
// @ts-check
const buckets = new Map();
/** 10 secondi */
const WINDOW_MS = 10_000;
const LIMIT = 100;
function rateLimit(req, res, next) {
const key = req.ip || 'global';
const now = Date.now();
const bucket = buckets.get(key) || { count: 0, ts: now };
if (now - bucket.ts > WINDOW_MS) {
bucket.count = 0;
bucket.ts = now;
}
bucket.count++;
buckets.set(key, bucket);
if (bucket.count > LIMIT) return res.status(429).json({ message: 'Troppo traffico, riprova tra poco.' });
next();
}
module.exports = { rateLimit };