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 => {
2018-06-29 02:58:51 +02: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 {
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 ;