-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (38 loc) · 965 Bytes
/
server.js
File metadata and controls
42 lines (38 loc) · 965 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
32
33
34
35
36
37
38
39
40
41
42
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 3001
app.use(cors())
app.use(express.static('public'))
const rappers = {
'21 savage':{
'age': 29,
'birthname': 'Shéyaa Bin Abraham-Joseph',
'birthLocation': 'London, England'
},
'chance the rapper':{
'age': 29,
'birthname': 'Chancelor Bennett',
'birthLocation': 'Chicago, Illinois'
},
'dylan':{
'age': 29,
'birthname': 'Dylan',
'birthLocation': 'Dylan'
}
}
app.get('/', (request, response)=>{
response.sendFile(__dirname + '/index.html')
})
app.get('/api/:rapperName', (request, response)=>{
const rappersName = request.params.rapperName.toLowerCase()
if(rappers[rappersName]){
response.json(rappers[rappersName])
}else{
response.json(rappers['dylan'])
}
//response.json(rappers)
})
app.listen(process.env.PORT || 3001, ()=>{
console.log(`The server is running on port ${process.env.PORT || 3001}! You better go catch it!`)
})