From 7172413e795a91e62d995d489e2583380a2b3b10 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sun, 1 Jun 2025 18:51:05 +0200 Subject: [PATCH] completed 3.7 --- parts/3/phonebookBackend/index.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/parts/3/phonebookBackend/index.js b/parts/3/phonebookBackend/index.js index c42f959..62f2b97 100644 --- a/parts/3/phonebookBackend/index.js +++ b/parts/3/phonebookBackend/index.js @@ -1,13 +1,6 @@ const express = require("express"); const app = express(); - -const requestLogger = (request, response, next) => { - console.log("Method:", request.method); - console.log("Path: ", request.path); - console.log("Body: ", request.body); - console.log("---"); - next(); -}; +const morgan = require("morgan"); const unknownEndpoint = (request, response) => { response.status(404).send({ error: "unknown endpoint" }); @@ -15,9 +8,7 @@ const unknownEndpoint = (request, response) => { app.use(express.json()); -app.use(requestLogger); - -app.use(unknownEndpoint); +app.use(morgan("tiny")); const persons = [ { @@ -128,6 +119,8 @@ app.get("/info", (request, response) => { response.send(responseString); }); +app.use(unknownEndpoint); + const PORT = 3001; app.listen(PORT, () => { console.log(`Server running on port ${PORT}`);