-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (49 loc) · 1.3 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
const express = require('express')
const bodyParser = require('body-parser')
const nunjucks = require('nunjucks')
const axios = require('axios').default
const envNunjucks = new nunjucks.Environment(new nunjucks.FileSystemLoader('templates'))
const app = express()
envNunjucks.express(app)
app.use('/assets',
express.static(__dirname + '/assets'),
express.static(__dirname + '/node_modules/materialize-css/dist'),
)
app.use('/assets/js',
express.static(__dirname + '/node_modules/jquery/dist')
)
app.use(bodyParser.urlencoded({
extended:true
}))
app.get('/surah/:surah', (req, res) => {
axios
.get(`http://api.alquran.cloud/surah/${req.params.surah}/ar.alafasy`)
.then(response => {
const {data} = response.data
const surah = data
console.log(surah)
res.render('detail.html', {
pageTitle: surah.englishName,
surah
})
})
.catch(err => {
console.error('ERR_RESPONSE', err)
res.send('ERR')
})
})
app.get('/', (req, res) => {
axios.get('http://api.alquran.cloud/surah')
.then(r => {
const {data} = r.data
res.render('index.html', {
pageTitle:'Index Page',
data
})
})
.catch(err => {
console.error('ERR_RESPONSE',err)
re.send('ERR')
})
})
app.listen(9696, () => console.log('server running on http://localhost:9696'))