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

View File

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

View File

@ -14,7 +14,7 @@ router.use(express.json());
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;
var feed = new Feed({
@ -44,7 +44,7 @@ router.get('/:site', utils.limiter(500), (req, res) => {
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 path = req.params[0];

View File

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

View File

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