From d5394e9c1a936e8272ed036f259532939d37f44f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 3 Jun 2017 14:26:31 -0400 Subject: pull db if possible --- client/src/lib/db/index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'client/src/lib/db/index.js') 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) }) -- cgit v1.2.3-70-g09d2