Relocated logging middleware
This commit is contained in:
parent
f9c7359fd6
commit
184ec7196d
|
@ -5,14 +5,12 @@ const express = require('express');
|
|||
const app = express();
|
||||
|
||||
const APIRoutes = require('./routes/api');
|
||||
const Loggerware = require('./middleware/Logger');
|
||||
|
||||
// Middleware to log requests
|
||||
app.use((req, res, next) => {
|
||||
let time = new Date().toLocaleTimeString();
|
||||
console.log(time + ' | Request received | path: ' + req.path + ' | method: ' + req.method);
|
||||
next();
|
||||
});
|
||||
// Set up middleware
|
||||
app.use(Loggerware);
|
||||
|
||||
// Set up API routes
|
||||
app.use(APIRoutes);
|
||||
|
||||
// Listen on port set in .env
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue