This commit is contained in:
newtbot
2024-01-04 15:32:46 +08:00
parent db1b513ad5
commit 1819956bd0
21 changed files with 1541 additions and 642 deletions

View File

@ -1,4 +1,3 @@
const { getAPIKey } = require('../db/ApiKeys');
function apiKeyMiddleware(req, res, next) {
const apiKey = req.headers['x-api-key'];

View File

@ -1,20 +1,24 @@
const { insertLogData } = require("../functions/Database.js");
const { insertLogData } = require("../functions/database.js");
const APIlogger = (req, res, next) => {
const log = {
ip: req.ip,
time: new Date().toUTCString(),
method: req.method,
//https://stackoverflow.com/questions/10183291/how-to-get-the-full-url-in-express
host: `${req.protocol}://${req.get("host")}${req.originalUrl}`,
statusCode: res.statusCode,
Responsesize: res.get('Content-Length') ? res.get('Content-Length') : 0,
referrer: res.get('content-type') ? res.get('content-type') : "none",
userAgent: req.headers["user-agent"],
};
//upload to db logic here for api logs
insertLogData(log);
next();
try {
const log = {
ip: req.ip,
time: new Date().toUTCString(),
method: req.method,
//https://stackoverflow.com/questions/10183291/how-to-get-the-full-url-in-express
host: `${req.protocol}://${req.get("host")}${req.originalUrl}`,
statusCode: res.statusCode,
Responsesize: res.get('Content-Length') ? res.get('Content-Length') : 0,
referrer: res.get('content-type') ? res.get('content-type') : "none",
userAgent: req.headers["user-agent"],
};
//upload to db logic here for api logs
insertLogData(log);
next();
}
catch (error) {
console.error(error);
}
};
module.exports = { APIlogger };