From f3be0b1d91b782b9dca406bad57027204383dddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Tue, 19 Mar 2024 00:31:21 +0300 Subject: [PATCH] galiba bu kez oldu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferit Yiğit BALABAN --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2c49f39..8f49318 100644 --- a/index.js +++ b/index.js @@ -30,12 +30,14 @@ app.use( }) ); -app.use((err, req, res, next) => { - if (err.message.startsWith('Origin')) { - res.status(403).json({ error: err.message }); +app.use((req, res, next) => { + const origin = req.headers.origin; + if (origin && allowedOrigins.includes(origin)) { + next(); } else { - next(err); - } + res.status(403).json({ success: false, message: `Origin ${origin} is not allowed` }); + console.warn(`Connection refused: origin ${origin} is not allowed`); + } }); // 2 requests per 5 minutes