-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (32 loc) · 1.07 KB
/
app.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
42
43
const express = require('express');
const app = express();
const morgan = require('morgan');
const cors = require("cors");
const mongoose = require("mongoose");
const coffeeRoute = require("./routes/coffee-route");
const userRoute = require("./routes/user-route");
const loginRoute = require("./routes/login-route");
const attRoute = require("./routes/atualizacao-route");
const db = 'mongodb+srv://tem-cafe:[email protected]/test?retryWrites=true&w=majority'
mongoose.connect(db, { useNewUrlParser: true })
.then(() => { console.log("MongoDB Connected") });
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cors());
app.use(morgan('dev'));
app.use('/tem-cafe', coffeeRoute);
app.use('/usuario', userRoute);
app.use('/login', loginRoute);
app.use('/verificarAtt', attRoute);
app.use((req, res, next) => {
const error = new Error("Route Not found");
error.status = 404;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: error.message
});
});
module.exports = app;