spee.ch/server/middleware/torCheckMiddleware.js

25 lines
522 B
JavaScript
Raw Normal View History

2018-06-27 14:23:14 -07:00
const logger = require('winston');
2018-06-27 17:56:28 -07:00
const db = require('../models');
2018-06-27 15:01:40 -07:00
2018-06-27 18:10:47 -07:00
const torCheck = (req, res, next) => {
const { ip } = req;
2018-06-27 17:56:28 -07: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-27 18:10:47 -07:00
req['tor'] = (result.length >= 1); // add this to the req object
next();
2018-06-27 17:56:28 -07:00
})
.catch(error => {
logger.error(error);
2018-06-27 15:01:40 -07:00
});
2018-06-27 14:23:14 -07:00
};
module.exports = torCheck;