-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (32 loc) · 905 Bytes
/
Copy pathserver.js
File metadata and controls
37 lines (32 loc) · 905 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
const express = require('express');
const app = express();
const cors = require('cors');
const PORT = 8000;
app.use(cors());
const rappers = {
'21 savage' :{
'age': 29,
'birthName': 'Shéyaa Bin Abraham-Joseph',
'birthLocation': 'London, England'
},
'chance the rapper':{
'age': 29,
'birthName': 'Chancelor Johnathan Bennett',
'birthLocation': 'Chicago, Illinois, U.S.'
},
'unknown':{
'age': 0,
'birthName': 'unknown',
'birthLocation': 'unknown'
}
}
app.get('/', (req, res) =>{
res.sendFile(__dirname + '/index.html');
})
app.get('/api/:name', (req, res) =>{
const rapperName = req.params.name.toLowerCase();
rappers[rapperName] ? res.json(rappers[rapperName]) : res.json(rappers['unknown']);
})
app.listen(process.env.PORT || PORT, () =>{
console.log(`Server running on port ${PORT}`)
})