-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (42 loc) · 1.19 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
//heroku URL https://sanrio-character-api.herokuapp.com/
const express = require('express')
const app = express()
const cors = require('cors')
const PORT = 8000
app.use(cors())
const characters = {
'hello kitty': {
'characterName': 'Hello Kitty',
'creationYear': 1974,
'distinctiveFeatures': 'trademark red bow',
},
'keroppi': {
'characterName': 'Keroppi',
'creationYear': 1987,
'distinctiveFeature': 'V-shaped mouth',
},
'kuromi': {
'characterName': 'Kuromi',
'creationYear': 2005,
'distinctiveFeature': 'black jester\'s hat '
},
'unknown': {
'characterName': 'unknown',
'creationYear': 0,
'distinctiveFeature': 'unknown',
}
}
app.get('/', (request,response) =>{
response.sendFile(__dirname + '/index.html')
})
app.get('/api/:name', (request,response) =>{
const characterName = request.params.name.toLowerCase()
if (characters [characterName]){
response.json(characters[characterName])
}else {
response.json(characters['unknown'])
}
})
app.listen(process.env.PORT || PORT, () =>{
console.log(`The server is now running on ${PORT}.`);
})