Create index.json

This commit is contained in:
Salman Qureshi
2025-04-30 01:51:14 +05:30
committed by GitHub
parent 0e7453b571
commit d97fbfd971
+29
View File
@@ -0,0 +1,29 @@
const express = require('express');
const rateLimit = require('express-rate-limit');
const fs = require('fs');
const app = express();
const PORT = process.env.PORT || 3000;
// Load reasons from JSON
const reasons = JSON.parse(fs.readFileSync('./reasons.json', 'utf-8'));
// Rate limiter: 10 requests per minute per IP
const limiter = rateLimit({
windowMs: 60 * 1000, // 1 minute
max: 10,
message: { error: "Too many requests, please try again later." }
});
app.use(limiter);
// Random rejection reason endpoint
app.get('/no', (req, res) => {
const reason = reasons[Math.floor(Math.random() * reasons.length)];
res.json({ reason });
});
// Start server
app.listen(PORT, () => {
console.log(`No-as-a-Service is running on port ${PORT}`);
});