-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (32 loc) · 860 Bytes
/
Copy pathserver.js
File metadata and controls
35 lines (32 loc) · 860 Bytes
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
const { response } = require('express')
const express = require('express')
const app = express()
const PORT = 8000
const motivationalPhrase = {
'quote1': {
'phrase': 'Today will be your day.',
'type' : 'positive'
},
'quote2': {
'phrase': 'You have the power to make a change in your life',
'type' : 'inspirational'
},
'default': {
'phrase': 'Today is a day',
'type' : 'funny'
}
}
app.get('/',(req, res) =>{
res.sendFile(__dirname + '/index.html')
})
app.get('/api:quote',(req,res) =>{
const quoteNum = req.params.quote
if(motivationalPhrase[quoteNum]){
res.json(motivationalPhrase['phrase'])
}else{
res.json(motivationalPhrase['default'])
}
})
app.listen(process.env.PORT || PORT, ()=> {
console.log(`The server is running on port ${PORT}.`)
})