completed 3.7
This commit is contained in:
parent
e35839318b
commit
7172413e79
1 changed files with 4 additions and 11 deletions
|
|
@ -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}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue