-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (23 loc) · 831 Bytes
/
app.js
File metadata and controls
31 lines (23 loc) · 831 Bytes
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
const express = require('express');
const { getSnacks, postSnack } = require('./controllers/snacksController');
const { getDrinkById } = require('./controllers/drinksController');
const app = express();
app.use(express.json());
app.get('/api', (req, res) => {
res.status(200).send({ msg: 'four little bears!!! ʕ•́ᴥ•̀ʔっʕ•́ᴥ•̀ʔっʕ•́ᴥ•̀ʔっʕ•́ᴥ•̀ʔっ' });
});
app.get('/api/snacks', getSnacks);
app.get('/api/drinks/:drink_id', getDrinkById);
app.post('/api/snacks', postSnack);
app.use((err, req, res, next) => {
if (err.status === 400) {
res.status(400).send({ msg: err.msg });
} else {
next(err);
}
});
app.use((err, req, res, next) => {
console.log(err); // debugging tool
res.status(500).send({ msg: "oops I did a bad soz :'( " });
});
module.exports = app;