forked from pikuba/programmeren-4-shareameal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 1002 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require("express");
const routerUser = require("./src/routes/user.routes");
const routerAuth = require("./src/routes/authentication.routes");
const routerMeal = require("./src/routes/meal.routes");
require("dotenv").config();
const app = express();
const port = process.env.PORT;
app.use(express.json());
//this function shows which function is called.
app.all("*", (req, res, next) => {
const method = req.method;
console.log(`Method ${method} is aangeroepen`);
next();
});
app.use(routerUser);
app.use(routerAuth);
app.use(routerMeal);
//function to give an error when an end-point isnt found
app.all("*", (req, res) => {
res.status(401).json({
status: 401,
result: "End-point not found",
});
});
app.use((err, req, res, next) => {
console.log("Error: " + err.toString());
res.status(400).json({
status: 400,
message: err.message,
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
module.exports = app;