-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (43 loc) · 1.36 KB
/
index.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
const express = require('express')
const path = require('path')
const axios = require('axios')
const app = express()
app.use(express.static(__dirname + '/src'));
const PORT = 3000
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'))
})
app.get('/activity', async (req, res) => {
try {
const response = await axios.get('http://www.boredapi.com/api/activity?type=recreational')
const activity = response.data.activity
res.json({ activity })
} catch (error) {
console.error(error)
res.status(500).json({ error: 'Error fetching activity' + error })
}
})
app.get('/freeActivity', async (req, res) => {
try {
const response = await axios.get('http://www.boredapi.com/api/activity?price=0.0')
const activity = response.data.activity
res.json({ activity })
} catch (error) {
console.error(error)
res.status(500).json({ error: 'Error fetching activity' + error })
}
})
app.get('/fetchQuote', async (req, res) => {
try {
const response = await axios.get('https://zenquotes.io/api/random')
const quote = response.data[0].q
const author = response.data[0].a
res.json({ quote, author })
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Erro ao buscar citação :/' + error })
}
})
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`)
})