summaryrefslogtreecommitdiff
path: root/client/src/lib/db/index.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-06-03 14:26:31 -0400
committerJules Laplace <julescarbon@gmail.com>2017-06-03 14:26:31 -0400
commitd5394e9c1a936e8272ed036f259532939d37f44f (patch)
tree428e07f6dcdc198fb4ec999e2e4eb72bceef87ad /client/src/lib/db/index.js
parentce8e9934191119e44d1520e2991439c2d94666ef (diff)
pull db if possible
Diffstat (limited to 'client/src/lib/db/index.js')
-rw-r--r--client/src/lib/db/index.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/client/src/lib/db/index.js b/client/src/lib/db/index.js
index 3fc6397..a60fa03 100644
--- a/client/src/lib/db/index.js
+++ b/client/src/lib/db/index.js
@@ -3,20 +3,30 @@ import { backupDB } from './backupDB';
function fetchDB(cb) {
let raw_db;
- fetch(hosts.db, {
+ fetch('/db.json', {
method: 'GET'
}).then(res => {
+ if (res.status !== 200) {
+ return null
+ }
return res.json()
}).then(json => {
- raw_db = parse(json)
+ if (json) {
+ raw_db = parse(json)
+ }
return fetch(hosts.comments, {
method: 'GET',
})
}).then(res => {
+ if (res.status !== 200) {
+ return null
+ }
return res.json()
}).then(json => {
- raw_db.comments = json.reverse()
- cb(raw_db)
+ if (json) {
+ raw_db.comments = json.reverse()
+ cb(raw_db)
+ }
}).catch((err) => {
console.warn(err)
})