Refactor discordWebhookSuspisiousAlertMiddleware.js to use setupData variable within the sendDiscordWebhook function
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
16
.drone.yml
16
.drone.yml
@@ -13,13 +13,27 @@ steps:
|
|||||||
- npm install
|
- npm install
|
||||||
- node -v
|
- node -v
|
||||||
|
|
||||||
|
- name: extract-version
|
||||||
|
image: node:alpine
|
||||||
|
commands:
|
||||||
|
- npm install -g json
|
||||||
|
- echo $(json -f package.json version) > .version
|
||||||
|
volumes:
|
||||||
|
- name: shared
|
||||||
|
path: /drone/src
|
||||||
|
|
||||||
- name: build-docker-image
|
- name: build-docker-image
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: swiftlogiclabs/cdn-app-insider
|
repo: swiftlogiclabs/cdn-app-insider
|
||||||
tags: latest
|
tags:
|
||||||
|
- latest
|
||||||
|
- $(cat .version)
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
volumes:
|
||||||
|
- name: shared
|
||||||
|
path: /drone/src
|
||||||
@@ -2,7 +2,6 @@ const axios = require('axios');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const setupFilePath = path.join(__dirname, '../data', 'setup.json');
|
const setupFilePath = path.join(__dirname, '../data', 'setup.json');
|
||||||
const setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
|
||||||
|
|
||||||
function sendDiscordWebhook(url, req, statusCode) {
|
function sendDiscordWebhook(url, req, statusCode) {
|
||||||
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
|
||||||
@@ -37,14 +36,11 @@ function sendDiscordWebhook(url, req, statusCode) {
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.post(url, data)
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(`Erreur lors de l'envoi du webhook à Discord: ${error}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function discordWebhookSuspisiousAlertMiddleware(req, res, next) {
|
function discordWebhookSuspisiousAlertMiddleware(req, res, next) {
|
||||||
|
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;
|
||||||
sendDiscordWebhook(discordWebhookUrl, req, res.statusCode);
|
sendDiscordWebhook(discordWebhookUrl, req, res.statusCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user