increase max request per IP
Browse files
server.js
CHANGED
|
@@ -23,6 +23,7 @@ const PORT = process.env.APP_PORT || 3000;
|
|
| 23 |
const REDIRECT_URI =
|
| 24 |
process.env.REDIRECT_URI || `http://localhost:${PORT}/auth/login`;
|
| 25 |
const MODEL_ID = "deepseek-ai/DeepSeek-V3-0324";
|
|
|
|
| 26 |
|
| 27 |
app.use(cookieParser());
|
| 28 |
app.use(bodyParser.json());
|
|
@@ -162,7 +163,7 @@ app.post("/api/ask-ai", async (req, res) => {
|
|
| 162 |
if (!hf_token) {
|
| 163 |
// Rate limit requests from the same IP address, to prevent abuse, free is limited to 2 requests per IP
|
| 164 |
ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
|
| 165 |
-
if (ipAddresses.get(ip) >
|
| 166 |
return res.status(429).send({
|
| 167 |
ok: false,
|
| 168 |
openLogin: true,
|
|
|
|
| 23 |
const REDIRECT_URI =
|
| 24 |
process.env.REDIRECT_URI || `http://localhost:${PORT}/auth/login`;
|
| 25 |
const MODEL_ID = "deepseek-ai/DeepSeek-V3-0324";
|
| 26 |
+
const MAX_REQUESTS_PER_IP = 4;
|
| 27 |
|
| 28 |
app.use(cookieParser());
|
| 29 |
app.use(bodyParser.json());
|
|
|
|
| 163 |
if (!hf_token) {
|
| 164 |
// Rate limit requests from the same IP address, to prevent abuse, free is limited to 2 requests per IP
|
| 165 |
ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
|
| 166 |
+
if (ipAddresses.get(ip) > MAX_REQUESTS_PER_IP) {
|
| 167 |
return res.status(429).send({
|
| 168 |
ok: false,
|
| 169 |
openLogin: true,
|