-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (59 loc) · 1.57 KB
/
server.js
File metadata and controls
65 lines (59 loc) · 1.57 KB
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
const express = require('express')
const app = express()
const PORT = 3008
const cors = require('cors')
app.use(express())
app.use(cors())
app.use(express.static('public'))
const cats = {
'persian': {
'breed': 'Persian',
'lifespan': '14 years - 15 years',
'img': './cat-img/persian-cat.jpg'
},
'siamese': {
'breed': 'Siamese',
'lifespan': '12 years - 15 years',
'img': './cat-img/siamese.jpg'
},
'norwegian forest': {
'breed': 'Norwegian Forest',
'lifespan': '12 years - 16 years',
'img': './cat-img/norwegian-forest-cat.jpg'
},
'russian blue': {
'breed': 'Russian Blue',
'lifespan': '10 years - 16 years',
'img': './cat-img/russian-blue.jpg'
},
'birman': {
'breed': 'Birman',
'lifespan': '14 years - 15 years',
'img': './cat-img/birman.jpg'
},
'not found': {
'breed': 'unknown',
'lifespan': 'unknown',
'img': './cat-img/unknown-photo.jpg'
}
}
app.get('/', (request,response) => {
response.sendFile(__dirname + '/public/index.html')
})
app.get('/', (request,response) => {
response.sendFile(__dirname + '/public/main.js')
})
app.get('/api', (request,response) => {
response.json(cats)
})
app.get('/api/:cat', (request,response) => {
const catProfile = request.params.cat.toLowerCase()
if(cats[catProfile]){
response.json(cats[catProfile])
} else {
response.json(cats['not found'])
}
})
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})