blah
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
const { getAPIKey } = require('../db/ApiKeys');
|
||||
|
||||
function apiKeyMiddleware(req, res, next) {
|
||||
const apiKey = req.headers['x-api-key'];
|
||||
|
@ -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 };
|
||||
|
Reference in New Issue
Block a user