-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (40 loc) · 908 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
44
45
46
47
const express = require('express');
const app = express();
const cors = require('cors');
const PORT = 8000;
app.use(cors());
const bDays = {
'frank':{
'birthday': '1960_05_07',
'team': 'Penn State',
'beer': 'Guinness'
},
'ron':{
'birthday': '1957_09_14',
'team': 'UGA',
'beer': 'Classic City Lager'
},
'no dad':{
'birthday': 'not born',
'team': 'no team',
'beer': 'heineken'
}
}
app.get('/', (req, res)=>{
res.sendFile(__dirname + '/index.html');
})
app.get('/api', (req, res)=>{
res.json(bDays);
})
app.get('/api/:name', (req, res)=>{
const name = req.params.name.toLowerCase();
if (bDays[name]){
res.json(bDays[name])
}
else{
res.json(bDays['no dad'])
}
})
app.listen(process.env.PORT || PORT, ()=>{
console.log(`Server is now running on port ${PORT}`)
})