npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tor-detect-middleware

v1.0.2

Published

Tor detect middleware for Express

Downloads

35

Readme

About

Tor detect middleware for Express.

❤️ Awesome Features:

  • Easy to redirect Tor or Surface users. 🔥
  • Easy to recognize TorUsers at inside the req object, req.isTorUser 🍺
  • No infra required, the database is json based using lowdb 🎉
  • The strictMode won't allow any request to access until the relays IPs are collected 📦
  • The purge allow you to dump the database at startup ☣️
  • debug is supported 💪
  • Refresh time is customizable 🧐
  • Easy to use and great test coverage ✅
const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler())

app.get('/', (req, res) => {
  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  res.send(`Are you (${ip}) a TOR user? ${req.isTorUser}`);
});

app.listen(3000, () => {
  console.log('We are in port 3000!');
});

Usage

Install

npm install tor-detect-middleware

simple example

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler())

app.get('/', (req, res) => {
  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  res.send(`Are you (${ip}) a TOR user? ${req.isTorUser}`);
});

app.listen(3000, () => {
  console.log('We are in port 3000!');
});

Redirect Users

In this example we redirect the surface users to https://www.nytimes.com and Tor users to https://www.nytimes3xbfgragh.onion/. You can use both ways to redirect.

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler({
    surface: "https://www.nytimes.com",
    tor: "https://www.nytimes3xbfgragh.onion/"
}))

app.listen(3000, () => {
  console.log('We are in port 3000!');
});

Ban users from surface or TOR

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler())

app.get('/surface-only', (req, res) => {
  if(req.isTorUser) return res.status(401).send("You can't access from TOR here")
  res.send('Welcome surface user!');
});

app.get('/tor-only', (req, res) => {
  if(!req.isTorUser) return res.status(401).send("You can't access from the surface here")
  res.send('Welcome to the dark side. We have cookies!');
});

app.listen(3000, () => {
  console.log('We are in port 3000!');
});

Custom Cron Jobs

By default we refresh the IP list every hour, but you can modify the ms as you wish.

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler({refreshMs: 600000}))

//...

Strict Mode

Special behaviour in Strict mode:

  • The server will stop at startup if https://onionoo.torproject.org/details url is down
  • The server will wait until there is a list ready to dispatch requests. (Few seconds)

Note: if there is a list stored you wont surfer any problem, as we start the service from the previous list.

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler({
    strictMode: true
}))

//...

Purge list at start

You can purge the list by default at the startup of the service.

const express = require('express');
const torUserHandler = require('tor-detect-middleware')
const app = express();

app.use(torUserHandler({
    purge: true
}))

//...

Built With

Development only:

Production only:

  • debug - Debug the app
  • got - Download TOR infra data
  • ip-regex - Validate relays IPs
  • lowdb - Store and query IPs

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the GNU AGPL3.0 License - see the LICENSE.md file for details

Acknowledgments

  • This project is under development, but you can help us to improve it! We :heart: FOSS!