-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
43 lines (37 loc) · 993 Bytes
/
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
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 8000
app.use(cors())
let rappers = {
'21 savage': {
'age': 28,
'birthName': 'Shéyaa Bin Abraham-Joseph',
'birthLocation': 'London, England'
},
'chance the rapper':{
'age': 27,
'birthName': 'Chancelor Jonathan Bennett',
'birthLocation': 'Chicago, Illinois'
},
'dylan':{
'age': 28,
'birthName': 'dylan',
'birthLocation': 'dylan'
}
}
app.get('/', (request, response) => {
response.sendFile(__dirname + '/index.html')
})
app.get('/api/rappers/:rapperName', (request, response)=>{
const rapName = request.params.rapperName.toLowerCase()
console.log(rapName)
if(rappers[rapName]){
response.json(rappers[rapName])
}else{
response.json(rappers['dylan'])
}
})
app.listen(process.env.PORT || PORT, ()=>{
console.log(`Server running on port ${PORT}`)
})