From 3786657cf2d185ea9e6b73c680d40a906820c02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Tue, 19 Mar 2024 00:19:37 +0300 Subject: [PATCH] only limit /api/mail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferit Yiğit BALABAN --- index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index eac694f..b12aa0a 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,6 @@ const limiter = rateLimit({ max: 2, }); -app.use(limiter); - const transporter = nodemailer.createTransport({ host: SERV_HOST, port: SERV_PORT, @@ -47,7 +45,7 @@ const transporter = nodemailer.createTransport({ }, }); -app.post('/api/mail', (req, res) => { +app.post('/api/mail', limiter, (req, res) => { const { to, subject, text } = req.body; const mail = { @@ -61,10 +59,10 @@ app.post('/api/mail', (req, res) => { if (ENV === 'PROD') { if (transporter.sendMail(mail)) { console.info('Sent something:', mail); - res.status(200).json({ message: 'Mail sent successfully!' }); + res.status(200).json({ success: true, message: 'Mail sent successfully!' }); } else { console.error('Failed to send:', mail); - res.status(500).json({ message: 'Mail could not be sent!' }); + res.status(500).json({ success: false, message: 'Mail could not be sent!' }); }; } else res.status(200).json(mail); });