diff --git a/backend/index.js b/backend/index.js index dac1190..6002700 100644 --- a/backend/index.js +++ b/backend/index.js @@ -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 diff --git a/backend/middleware/logger.js b/backend/middleware/logger.js new file mode 100644 index 0000000..3c841a3 --- /dev/null +++ b/backend/middleware/logger.js @@ -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; \ No newline at end of file