Update middleware/midware.js
Browse files- middleware/midware.js +25 -0
middleware/midware.js
CHANGED
@@ -39,6 +39,30 @@ const authenticateApiKeyPremium = async (req, res, next) => {
|
|
39 |
}
|
40 |
};
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
const authenticateApiKey = async (req, res, next) => {
|
43 |
const apiKey = req.headers['x-api-key'];
|
44 |
const dbClient = new Database("AkenoXJs");
|
@@ -141,6 +165,7 @@ class CheckMilWare {
|
|
141 |
export {
|
142 |
CheckMilWare,
|
143 |
authenticateApiKey,
|
|
|
144 |
authenticateApiKeyPremium,
|
145 |
apiLimiter
|
146 |
};
|
|
|
39 |
}
|
40 |
};
|
41 |
|
42 |
+
const authenticateApiKeyDev = async (req, res, next) => {
|
43 |
+
const apiKey = req.headers['x-api-key'];
|
44 |
+
const dbClient = new Database("AkenoXJs");
|
45 |
+
const db = dbClient.collection("api_keys_dev");
|
46 |
+
if (!apiKey) {
|
47 |
+
return res.status(401).json({ error: 'API Key required' });
|
48 |
+
}
|
49 |
+
|
50 |
+
try {
|
51 |
+
const keyDoc = await db.findOne({key: apiKey});
|
52 |
+
if (!keyDoc) {
|
53 |
+
return res.status(403).json({ error: 'Invalid API Key Dev' });
|
54 |
+
}
|
55 |
+
if (keyDoc.is_banned === true) {
|
56 |
+
return res.status(403).json({ error: 'Banned API Key' });
|
57 |
+
}
|
58 |
+
|
59 |
+
next();
|
60 |
+
} catch (err) {
|
61 |
+
res.status(500).json({ error: 'Server error' });
|
62 |
+
}
|
63 |
+
};
|
64 |
+
|
65 |
+
|
66 |
const authenticateApiKey = async (req, res, next) => {
|
67 |
const apiKey = req.headers['x-api-key'];
|
68 |
const dbClient = new Database("AkenoXJs");
|
|
|
165 |
export {
|
166 |
CheckMilWare,
|
167 |
authenticateApiKey,
|
168 |
+
authenticateApiKeyDev,
|
169 |
authenticateApiKeyPremium,
|
170 |
apiLimiter
|
171 |
};
|