Moonito - Website Security, Traffic Filtering and Analytics Made Easy
Moonito is a Node.js and TypeScript module built for web protection, traffic filtering, and analytics. It safeguards your application by detecting and blocking potentially harmful traffic based on IP, user agents, and visitor behavior. With Moonito, you can shield your website from bots, competitors, and unwanted traffic, all while gaining actionable insights into your audience.
To use Moonito, you need an API key and a subscription to the Moonito service. For more details, review our Moonito documentation.
Installation
Install Moonito using npm:
npm install moonito
Usage
Method 1: Using Express Middleware
import express from 'express';
import { VisitorTrafficFiltering } from 'moonito';
const app = express();
const port = 3000;
const config = {
isProtected: true,
apiPublicKey: 'Your API Public Key',
apiSecretKey: 'Your API Secret Key',
unwantedVisitorTo: 'https://google.com',
unwantedVisitorAction: 1
};
const filter = new VisitorTrafficFiltering(config);
app.use(async (req, res, next) => {
try {
await filter.evaluateVisitor(req, res);
} catch (error) {
return next(error);
}
next(!res.headersSent ? undefined : null);
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Method 2: Manually Providing IP, User-Agent, Events, and Domain
const { VisitorTrafficFiltering } = require('moonito');
const config = {
isProtected: true,
apiPublicKey: 'Your API Public Key',
apiSecretKey: 'Your API Secret Key',
unwantedVisitorTo: 'https://google.com',
unwantedVisitorAction: 1
};
const filter = new VisitorTrafficFiltering(config);
const userIP = '1.1.1.1';
const userAgent = 'Mozilla/5.0 ...';
const event = 'page-view';
const domain = 'example.com';
filter.evaluateVisitorManually(userIP, userAgent, event, domain)
.then(result => {
console.log('Visitor evaluation result:', result);
if (result.need_to_block) {
console.log('Blocked content:', result.content);
return;
}
console.log('Visitor is not blocked.');
})
.catch(error => {
console.error('Unexpected error:', error);
});
Replace Your API Public Key
and Your API Secret Key
with your actual Moonito API credentials in both methods.
Contributing
We welcome contributions! For significant changes, please open an issue to discuss the proposed modifications. Make sure to update tests as necessary.
License
This project is licensed under the MIT license.