aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/backends/static.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/backends/static.js')
-rw-r--r--web/src/js/backends/static.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/web/src/js/backends/static.js b/web/src/js/backends/static.js
new file mode 100644
index 00000000..6657fecf
--- /dev/null
+++ b/web/src/js/backends/static.js
@@ -0,0 +1,33 @@
+/*
+ * This backend uses the REST API only to host static instances,
+ * without any Websocket connection.
+ */
+import { fetchApi } from "../utils"
+
+export default class StaticBackend {
+ constructor(store) {
+ this.store = store
+ this.onOpen()
+ }
+
+ onOpen() {
+ this.fetchData("settings")
+ this.fetchData("flows")
+ this.fetchData("events")
+ this.fetchData("options")
+ }
+
+ fetchData(resource) {
+ fetchApi(`/${resource}`)
+ .then(res => res.json())
+ .then(json => {
+ this.receive(resource, json)
+ })
+ }
+
+ receive(resource, data) {
+ let type = `${resource}_RECEIVE`.toUpperCase()
+ this.store.dispatch({ type, cmd: "receive", resource, data })
+ }
+
+}