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 => {
2018-06-28 17:58:51 -07:00
if ( result . length >= 1 ) {
logger . info ( 'Tor request blocked:' , ip ) ;
const failureResponse = {
success : false ,
message : 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.' ,
} ;
res . status ( 403 ) . json ( failureResponse ) ;
} else {
2018-07-02 15:27:42 -07:00
return next ( ) ;
2018-06-28 17:58:51 -07:00
}
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 ;