forked from Rosem10/nc_snacks_example
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
33 lines (21 loc) · 910 Bytes
/
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
const express = require('express');
const app = express();
const { getSnacks, getSnackBySnackId, postSnack } = require('./controllers/snacks.controllers');
const { getVendingMachines, getVendingMachineById } = require('./controllers/vending-machines.controllers');
const { psqlErrorHandler, customErrorHandler, serverErrorHandler } = require('./error-handlers');
app.use(express.json())
app.get('/api', (request, response) => {
response.status(200).send({ message: 'Hello world!' })
})
app.get('/api/snacks', getSnacks)
app.get('/api/snacks/:snack_id', getSnackBySnackId)
app.post('/api/snacks', postSnack)
app.get('/api/venders', getVendingMachines)
app.get('/api/venders/:venderId', getVendingMachineById)
app.all('/*', (req, res) => {
res.status(404).send({ msg: 'Route not found' });
})
app.use(psqlErrorHandler)
app.use(customErrorHandler)
app.use(serverErrorHandler)
module.exports = app