-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
171 lines (144 loc) · 4.3 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const express = require('express')
const axios = require('axios')
const cors = require('cors')
const jsSearchArray = require('js-search-array')
const app = express()
const port = process.env.PORT || 4000
const gopay = "08995247131"
app.use(cors())
app.get('/', (req, res) => {
res.json({
author: "Alwan (wanrabbae) :)",
Title: "Alqur'an Bahasa Indonesia",
Deskripsi: "API gratis untuk Al-qur'an bahasa indonesia yg dibuat dengan cinta dan kasih sayang:), Salam Muslim. Masya allah",
Docs: "https://github.com/wanrabbae/al-quran-indonesia-api",
Donate: {
Gopay: gopay
},
})
})
app.get('/surah', async (req, res) => {
try {
const listSurat = await axios.get('https://api.npoint.io/99c279bb173a6e28359c/data')
res.json({
author: "Alwan (wanrabbae) :)",
status: "success",
Donate: {
Gopay: gopay
},
data: listSurat.data
})
} catch (err) {
res.status(500).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Server sedang error :(",
Donate: {
Gopay: gopay
},
})
}
})
app.get('/surah/:nosurat', async (req, res) => {
try {
if (req.params.nosurat >= 115) {
res.status(404).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
Donate: {
Gopay: gopay
},
message: "Al-quran hanya sampai 114 surah",
data: []
})
return false
}
const surat = await axios.get(`https://api.npoint.io/99c279bb173a6e28359c/surat/${req.params.nosurat}`)
res.json({
author: "Alwan (wanrabbae) :)",
status: "success",
Donate: {
Gopay: gopay
},
data: surat.data
})
} catch (err) {
res.status(500).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Server sedang error :(",
Donate: {
Gopay: gopay
},
})
}
})
app.get('/surat/:namasurat', async (req, res) => {
try {
const listSurat = await axios.get('https://api.npoint.io/99c279bb173a6e28359c/data')
const listSurat2 = JSON.parse(JSON.stringify(listSurat.data))
const findSurah = listSurat2.find(surah => surah.nama == req.params.namasurat)
if (!findSurah) return res.status(404).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Surah tidak ditemukan",
Donate: {
Gopay: gopay
},
})
res.json({
author: "Alwan (wanrabbae) :)",
status: "success",
Donate: {
Gopay: gopay
},
data: findSurah
})
} catch (err) {
res.status(500).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Server sedang error :(",
Donate: {
Gopay: gopay
},
})
}
})
// search surah
app.get('/surah/search/:namasurah', async (req, res) => {
try {
const listSurat = await axios.get('https://api.npoint.io/99c279bb173a6e28359c/data')
const listSurat2 = JSON.parse(JSON.stringify(listSurat.data))
const findSurah = jsSearchArray(req.params.namasurah, listSurat2, 'nama')
res.json({
author: "Alwan (wanrabbae) :)",
status: "success",
Donate: {
Gopay: gopay
},
data: findSurah
})
} catch (err) {
res.status(500).json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Server sedang error :(",
Donate: {
Gopay: gopay
},
})
}
})
// middleware
app.get('*', (req, res) => {
res.json({
author: "Alwan (wanrabbae) :)",
status: "failed",
message: "Error 404 Halaman tidak ditemukan!!",
Donate: {
Gopay: gopay
},
})
})
app.listen(port, () => console.log(`Server berjalan di http://localhost:${port}`))