-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
66 lines (59 loc) · 1.79 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// const { request, response } = require('express')
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 3000
app.use(cors())
const skiResorts ={
'blue mountain':{
'location': 'Collingwood, Ontario',
'top elevation': '450 m or 1,480ft',
'skiable area': '364 acres',
'number of runs': '42',
'lift capacity': '26,750 per hour',
'longest run': '1.6kms'
},
'banff sunshine':{
'location': 'Banff National Park, Alberta, Canada',
'top elevation': '2,730m m or 8,957ft',
'skiable area': '13.6 km2 (3,360.6 acres)',
'number of runs': '120',
'lift capacity': '20,000 per hour',
'longest run': '8kms or 5 miles'
},
'lake louise ski resort':{
'location': 'Lake Louise, Alberta, Canada',
'top elevation': '2,637m or 8,650ft',
'skiable area': '17 km2 (6.6 sq mi)',
'number of runs': '145',
'lift capacity': '14,000 per hour',
'longest run': '8kms or 5 miles',
'run breakdown':{
'green':'17',
'blue': '25',
'black': '54',
'double black': '43'
}
},
'unknown':{
' unknown': 'Please enter a known ski resort'
}
}
app.get('/', (request,response) =>{
response.sendFile(__dirname + '/index.html')
})
app.get('/api/:id', (request,response) =>{
let id = request.params.id.toLocaleLowerCase()
if(skiResorts[id]){
response.json(skiResorts[id])
}else{
response.json(skiResorts['unknown'])
}
response.json(skiResorts)
})
app.get('/api', (request,response) =>{
response.json(skiResorts)
})
app.listen(process.env.PORT || PORT, () =>{
console.log(`Your server is running on port ${process.env.PORT || PORT}`)
})