express-tor-detection
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

express-tor-detection

ExpressJS middlewear to manage users connecting from a TOR exit node

License Version Downloads

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!

Package Sidebar

Install

npm i express-tor-detection

Weekly Downloads

1

Version

1.1.0

License

MIT License

Unpacked Size

17.3 kB

Total Files

9

Last publish

Collaborators

  • easton36