spee.ch/server/middleware/torCheckMiddleware.js

25 lines
522 B
JavaScript
Raw Normal View History

2018-06-27 23:23:14 +02:00
const logger = require('winston');
2018-06-28 02:56:28 +02:00
const db = require('../models');
2018-06-28 00:01:40 +02:00
2018-06-28 03:10:47 +02:00
const torCheck = (req, res, next) => {
const { ip } = req;
2018-06-28 02:56:28 +02:00
logger.debug(`tor check for: ${ip}`);
return db.Tor.findAll(
{
where: {
address: ip,
},
raw: true,
})
.then(result => {
logger.debug('tor check results:', result);
2018-06-28 03:10:47 +02:00
req['tor'] = (result.length >= 1); // add this to the req object
next();
2018-06-28 02:56:28 +02:00
})
.catch(error => {
logger.error(error);
2018-06-28 00:01:40 +02:00
});
2018-06-27 23:23:14 +02:00
};
module.exports = torCheck;