-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (56 loc) · 1.47 KB
/
server.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const express = require('express')
const cors = require('cors')
const PORT = process.env.MONGOPORT || 3001
const db = require('./db/db')
const { Artist, Concert, Venue } = require('./models/index')
const app = express()
app.use(cors())
app.use(express.json())
app.get('/', (req, res) => {
res.send('This is the Sad Dads root!')
})
app.get('/artists', async (req, res) => {
const artists = await Artist.find({})
res.json(artists)
})
app.get('/artists/:id', async (req, res) => {
try {
const { id } = req.params
const artist = await Artist.findById(id)
res.json(artist)
} catch (e) {
console.log(e)
res.send('Artist not found!')
}
})
app.get('/concerts', async (req, res) => {
const concerts = await Concert.find({})
res.json(concerts)
})
app.get('/concerts/:id', async (req, res) => {
try {
const { id } = req.params
const concert = await Concert.findById(id)
res.json(concert)
} catch (e) {
console.log(e)
res.send('Concert not found!')
}
})
app.get('/venues', async (req, res) => {
const venues = await Venue.find({})
res.json(venues)
})
app.get('/venues/:id', async (req, res) => {
try {
const { id } = req.params
const venue = await Venue.findById(id)
res.json(venue)
} catch (e) {
console.log(e)
res.send('Venue not found!')
}
})
app.listen(PORT, () => {
console.log(`Express server listening on port ${PORT}`)
})