Moonito - Traffic Filtering and Analytics Made Easy
Moonito is a Node.js and TypeScript module designed for traffic filtering and analytics. It helps protect your application by evaluating and blocking potentially malicious traffic based on IP, User-Agent, and visitor activity information. With Moonito, you can safeguard your website from bots, competitors, and unwanted traffic while gaining valuable insights about your visitors. 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 -s
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 trafficFiltering = new VisitorTrafficFiltering(config);
app.use(async (req, res, next) => {
try {
await trafficFiltering.evaluateVisitor(req, res);
if (!res.headersSent) {
return next();
}
} catch (error) {
next(error);
}
});
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 trafficFiltering = new VisitorTrafficFiltering(config);
const userIP = '1.1.1.1';
const userAgent = 'Mozilla/5.0 ...';
const event = 'page-view';
const domain = 'npm-test.dev';
trafficFiltering.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.