-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (43 loc) · 1.15 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
const { request } = require('express')
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 8000
app.use(cors())
const rappers = {
'21 savage': {
'age' : 29,
'birthName': 'Sheyaa Bin Abraham-Joseph',
'birthLocation': 'London, England'
},
'chance the rapper': {
'age' : 29,
'birthName': 'chancelor Bennet',
'birthLocation': 'Chicago, US'
},
'unknown': {
'age' : 0,
'birthName': 'unknown',
'birthLocation': 'unknown'
},
'eminem': {
'age' : 49,
'birthName': 'Marshall Bruce Mathers III',
'birthLocation': ' Saint Joseph, Missouri, United States'
}
}
app.get('/', (request, response)=> {
response.sendFile(__dirname + '/index.html')
})
app.get('/api/:rapperName', (request, response) =>{
let rapperName = request.params.rapperName.toLocaleLowerCase();
if (rappers[rapperName]){
response.json(rappers[rapperName])
}
else{
response.json(rappers['unknown'])
}
})
app.listen(process.env.PORT || PORT, ()=>{
console.log(`The server is running on ${PORT}!`)
})