diff options
Diffstat (limited to 'client/src/lib/db/index.js')
| -rw-r--r-- | client/src/lib/db/index.js | 18 |
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) }) |
