express-tor-detection
v1.1.0
Published
ExpressJS middlewear to manage users connection from a TOR exit node
Downloads
3
Maintainers
Readme
express-tor-detection
ExpressJS middlewear to manage users connecting from a TOR exit node
Read more about TOR exit node detection: here
Read more about using middlewear with Express here
Installation
Installation is done using the
npm install
command:
$ npm install express-tor-detection
Usage
const express = require('express');
const torDetectionMiddlewear = require('express-tor-detection');
const middlewearConfig = {
block: true, // block TOR exit node requests
userKey: 'isTor', // req.isTor = true
errorMessage: 'TOR connections are not allowed!', // Error message to throw if block is set to true
redirect: { //these options will only apply if block is set to false
clearNetDomain: 'example.com', // domain name for clearnet traffic
torDomain: 'example.onion', //domain name for tor traffic
redirectClearNet: false, //redirect clearnet traffic if accessing from tor domain
redirectTor: true, //redirect tor traffic if accessing from clearnet domain
}
};
const app = express();
app.get('/', torDetectionMiddlewear(middlewearConfig), (req, res) => {
console.log(req.isTor); // false
res.send('You are not using TOR!');
});
app.listen(process.env.port || 3000, () => {
console.log(`Example app listening on port ${process.env.port || 3000}`);
});
Example
View the example! Feel free to fork and submit your own!