Relocated logging middleware

This commit is contained in:
Wilkozx 2024-08-04 18:23:21 +01:00
parent f9c7359fd6
commit 184ec7196d
2 changed files with 15 additions and 6 deletions

View File

@ -5,14 +5,12 @@ const express = require('express');
const app = express(); const app = express();
const APIRoutes = require('./routes/api'); const APIRoutes = require('./routes/api');
const Loggerware = require('./middleware/Logger');
// Middleware to log requests // Set up middleware
app.use((req, res, next) => { app.use(Loggerware);
let time = new Date().toLocaleTimeString();
console.log(time + ' | Request received | path: ' + req.path + ' | method: ' + req.method);
next();
});
// Set up API routes
app.use(APIRoutes); app.use(APIRoutes);
// Listen on port set in .env // Listen on port set in .env

View File

@ -0,0 +1,11 @@
const express = require('express');
const Loggerware = express.Router();
Loggerware.use((req, res, next) => {
let time = new Date().toLocaleTimeString();
console.log(time + ' | Request received | path: ' + req.path + ' | method: ' + req.method);
next();
});
module.exports = Loggerware;