const http = require("http");
const rateLimit = require("http-ratelimit");
http.createServer((req, res) => {
rateLimit.inboundRequest(req);
if(rateLimit.isRateLimited(req, 20) === true) {
res.writeHead(429, {"Content-Type": "text/plain; utf-8"});
res.end("Too many requests - max is 20 requests in two minutes");
}
else {
res.writeHead(200, {"Content-Type": "text/plain; utf-8"});
res.end("https://data.whicdn.com/images/325197845/superthumb.jpg");
}
}).listen(80, null, err => {
if(!err) {
rateLimit.init(2, true);
console.log("success");
}
else {
console.log(`Error: ${err}`);
process.exit(1);
}
});