UNPKG

wallids-api

Version:

Wallids Service - Node API

44 lines (36 loc) 1.25 kB
"use strict"; const axios = require('axios'); const Options = require('./options'); class Wallids { constructor(secretKey, options) { this.secretKey = secretKey; this.options = options ? options : [] } static tracing(constructor){ return function tracingHandler(req, res, next){ const parseIp = (typeof req.headers['x-forwarded-for'] === 'string' && req.headers['x-forwarded-for'].split(',').shift()) || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; const dataset = { "secretKey": constructor.secretKey, "info":{ "requestType": req.method, "request": req.method === 'GET' ? `${req.protocol}://${req.get('host')}${req.originalUrl}` : req.body, "ip": parseIp, "url": `${req.protocol}://${req.get('host')}` } }; axios.post('https://api.wallids.com/tracing/client', dataset) .then(result => { if(result.data.attack === 0){ next(); }else{ Options(constructor.options, res, next); } }).catch(err => next()); }; } } module.exports = Wallids;