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 express = require("express");
|
||||||
const app = express();
|
const app = express();
|
||||||
|
const morgan = require("morgan");
|
||||||
const requestLogger = (request, response, next) => {
|
|
||||||
console.log("Method:", request.method);
|
|
||||||
console.log("Path: ", request.path);
|
|
||||||
console.log("Body: ", request.body);
|
|
||||||
console.log("---");
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
const unknownEndpoint = (request, response) => {
|
const unknownEndpoint = (request, response) => {
|
||||||
response.status(404).send({ error: "unknown endpoint" });
|
response.status(404).send({ error: "unknown endpoint" });
|
||||||
|
|
@ -15,9 +8,7 @@ const unknownEndpoint = (request, response) => {
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
app.use(requestLogger);
|
app.use(morgan("tiny"));
|
||||||
|
|
||||||
app.use(unknownEndpoint);
|
|
||||||
|
|
||||||
const persons = [
|
const persons = [
|
||||||
{
|
{
|
||||||
|
|
@ -128,6 +119,8 @@ app.get("/info", (request, response) => {
|
||||||
response.send(responseString);
|
response.send(responseString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(unknownEndpoint);
|
||||||
|
|
||||||
const PORT = 3001;
|
const PORT = 3001;
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server running on port ${PORT}`);
|
console.log(`Server running on port ${PORT}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue