-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (66 loc) · 2.34 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require('express')
const nkjv = require('./nkjv.json')
const nasb = require('./nasb.json')
const esv = require('./esv.json')
const litv = require('./litv.json')
const geneva = require('./geneva.json')
require("dotenv").config()
const port = process.env.PORT || 8080
const app = express()
let bible = nkjv
// TODO wrap Obadiah, Philemon, 2 & 3 John, Jude in array for chapters
function getBibleVersion(version) {
switch (version) {
case 'esv':
bible = esv
break
case 'litv':
bible = litv
break
case 'geneva':
bible = geneva
break
case 'nasb':
bible = nasb
break
case 'nkjv':
bible = nkjv
break
default:
bible = nkjv
}
}
app.get('/', (req, res) => {
res.status(200).send("The API is working. Please add the bible suffix /NKJV, /NASB, /LITV, /ESV or /GENEVA to the path.")
})
app.get('/:version', (req, res) => {
res.json(bible)
})
app.get('/:version/:book', async (req, res) => {
getBibleVersion(req.params.version)
const bookName = req.params.book.toLowerCase().replace(' ', '')
console.log(`Retrieving ${req.params.version.toUpperCase()} ${req.params.book}`)
const json = await bible.books.filter(book => book.name.toLowerCase().replace(' ', '') === bookName)
res.json(json[0])
})
app.get('/:version/:book/:chapter', async (req, res) => {
getBibleVersion(req.params.version)
const bookName = req.params.book.toLowerCase().replace(' ', '')
const chapter = Number(req.params.chapter)
console.log(`Retrieving ${req.params.version.toUpperCase()} ${req.params.book} ${chapter}`)
const json = await bible.books.filter(book => book.name.toLowerCase().replace(' ', '') === bookName)
res.json(json[0].chapters[chapter - 1])
})
app.get('/:version/:book/:chapter/:verse', async (req, res) => {
getBibleVersion(req.params.version)
const bookName = req.params.book.toLowerCase().replace(' ', '')
const chapter = Number(req.params.chapter)
const verse = Number(req.params.verse)
console.log(`Retrieving ${req.params.version.toUpperCase()} ${req.params.book} ${chapter}:${verse}`)
const json = await bible.books.filter(book => book.name.toLowerCase().replace(' ', '') === bookName)
res.json(json[0].chapters[chapter - 1].verses[verse - 1])
})
app.listen(port, () => {
console.log(`Server is running on port :${port}`)
})
module.exports = app