Refactor discordWebhookSuspisiousAlertMiddleware.js to handle empty webhook URL
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,6 +4,10 @@ const path = require('path');
|
|||||||
const setupFilePath = path.join(__dirname, '../data', 'setup.json');
|
const setupFilePath = path.join(__dirname, '../data', 'setup.json');
|
||||||
|
|
||||||
function sendDiscordWebhook(url, req, statusCode) {
|
function sendDiscordWebhook(url, req, statusCode) {
|
||||||
|
if (!url) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||||
|
|
||||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
@@ -36,10 +40,16 @@ function sendDiscordWebhook(url, req, statusCode) {
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
axios.post(url, data)
|
||||||
|
.then(response => {
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function discordWebhookSuspisiousAlertMiddleware(req, res, next) {
|
function discordWebhookSuspisiousAlertMiddleware(req, res, next) {
|
||||||
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
||||||
|
|
||||||
|
|
||||||
res.on('finish', () => {
|
res.on('finish', () => {
|
||||||
const discordWebhookUrl = setupData[0].webhooks_discord;
|
const discordWebhookUrl = setupData[0].webhooks_discord;
|
||||||
|
|||||||
Reference in New Issue
Block a user