-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
68 lines (63 loc) · 1.57 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
67
68
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 8000
app.use(cors())
const hosts = {
'qatar' : {
'champion':'Argentina',
'runner-up':'France',
'third-place':'Croatia',
'host':'Qatar'
},
'russia' : {
'champion':'France',
'runner-up':'Croatia',
'third-place':'Belgum',
'host':'Russia'
},
'brazil' : {
'champion':'Genrmany',
'runner-up':'Argentina',
'third-place':'Netherlands',
'host':'Brazil'
},
'southafrica' : {
'champion':'Spain',
'runner-up':'Netherlands',
'third-place':'Germany',
'host':'South Africa'
},
'germany' : {
'champion':'Italy',
'runner-up':'France',
'third-place':'Germany',
'host':'Germany'
},
'southkoreajapan' : {
'champion':'Brazil',
'runner-up':'Germany',
'third-place':'Turkey',
'host':'South Korea, Japan'
},
'unknown' : {
'champion':'unknown',
'runner-up':'unknown',
'third-place':'unknown',
'host':'unknown'
}
}
app.get('/', (request, response)=>{
response.sendFile(__dirname + '/index.html')
})
app.get('/api/:host', (request, response) => {
const host = request.params.host.toLowerCase()
if (hosts[host]) {
response.json(hosts[host])
} else {
response.json(hosts['unknown'])
}
})
app.listen(process.env.PORT || PORT, ()=>{
console.log(`The server is running on port ${PORT}! You better go catch it!`)
})