Skip to content

Commit 699cba3

Browse files
committed
added write support via rest.
1 parent 1d0fb18 commit 699cba3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/fslib.browser.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ function readDB(path)
2828

2929
function writeDB(path, jsonStr)
3030
{
31-
return Promise.reject(new UnsupportedInBrowserError('writeDB()'));
31+
return fetch(path, {
32+
method: 'POST',
33+
mode: 'cors',
34+
headers: { 'Content-Type': 'application/json' },
35+
body: jsonStr
36+
})
37+
.then((data) => data.json())
38+
.catch((err) =>
39+
{
40+
const error = new Error(`Failed to post to '${ path }'.`);
41+
error.innerException = err;
42+
error.code = 'ERR_POST';
43+
44+
console.error(err);
45+
throw error;
46+
});
3247
} // end writeDB
3348

3449
//----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)