aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-11-12 15:37:34 -0800
committerAdam Soltys <[email protected]>2020-11-12 15:37:34 -0800
commit92e913ba9238bbc6aab147515631328db3f8b7f3 (patch)
treea08a5864affa35bf5839317d261d1ef1c0d3599e /lib
parent42ad55c926902587affc34a484396a00e16d534e (diff)
downloadcoinos-server-92e913ba9238bbc6aab147515631328db3f8b7f3.tar.gz
coinos-server-92e913ba9238bbc6aab147515631328db3f8b7f3.zip
persist lnurl data between server restarts
Diffstat (limited to 'lib')
-rw-r--r--lib/persist.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/persist.js b/lib/persist.js
new file mode 100644
index 00000000..24d00693
--- /dev/null
+++ b/lib/persist.js
@@ -0,0 +1,18 @@
+fs = require("fs");
+
+module.exports = (path, initial = {}) => {
+ try {
+ return require("../" + path);
+ } catch {
+ return new Proxy(initial, {
+ set(obj, prop, value) {
+ fs.writeFileSync(
+ path,
+ JSON.stringify({ ...obj, [prop]: value }, null, 2),
+ "utf-8"
+ );
+ return Reflect.set(...arguments);
+ }
+ });
+ }
+};