statebus 6.1.4 → 6.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +39 -8
- package/statebus.js +2 -0
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -99,24 +99,55 @@ function import_server (bus, options)
|
|
|
99
99
|
// User will put their routes in here
|
|
100
100
|
bus.express.use('/', bus.http)
|
|
101
101
|
|
|
102
|
+
// Use braidify if it's available
|
|
103
|
+
try {
|
|
104
|
+
var braidify = require('braidify').http_server
|
|
105
|
+
console.log('Found braidify library. Braid-HTTP enabled!')
|
|
106
|
+
} catch (e) {
|
|
107
|
+
var braidify = undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
102
110
|
// Add a fallback that goes to state
|
|
103
111
|
bus.express.get('*', function (req, res) {
|
|
104
112
|
// Make a temporary client bus
|
|
105
113
|
var cbus = bus.bus_for_http_client(req, res)
|
|
114
|
+
var cb
|
|
115
|
+
function end_it_all () {
|
|
116
|
+
cbus.forget(key, cb)
|
|
117
|
+
cbus.delete_bus()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
braidify && braidify(req, res)
|
|
121
|
+
if (req.subscribe) {
|
|
122
|
+
res.startSubscription({ onClose: end_it_all })
|
|
123
|
+
console.log('yay subscription!')
|
|
124
|
+
} else
|
|
125
|
+
res.statusCode = 200
|
|
106
126
|
|
|
107
127
|
// Do the fetch
|
|
108
128
|
cbus.honk = 'statelog'
|
|
109
|
-
var
|
|
110
|
-
cbus.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
var key = req.path.substr(1)
|
|
130
|
+
cbus.fetch(key, cb = (o) => {
|
|
131
|
+
if (braidify)
|
|
132
|
+
res.sendVersion({body: bus.to_http_body(o)})
|
|
133
|
+
else
|
|
134
|
+
res.send(bus.to_http_body(o))
|
|
135
|
+
|
|
136
|
+
if (!braidify || !req.subscribe)
|
|
137
|
+
end_it_all()
|
|
117
138
|
})
|
|
118
139
|
})
|
|
119
140
|
|
|
141
|
+
// Set up default linked json converters
|
|
142
|
+
bus.to_http_body = (o) => {
|
|
143
|
+
var unwrap = (Object.keys(o).length === 2
|
|
144
|
+
&& '_' in o
|
|
145
|
+
&& typeof o._ === 'string')
|
|
146
|
+
// To do: translate pointers as keys
|
|
147
|
+
return unwrap ? o._ : JSON.stringify(o)
|
|
148
|
+
}
|
|
149
|
+
bus.from_http_body = (o) => {}
|
|
150
|
+
|
|
120
151
|
// Serve Client Coffee
|
|
121
152
|
bus.serve_client_coffee()
|
|
122
153
|
|
package/statebus.js
CHANGED
|
@@ -2205,6 +2205,8 @@
|
|
|
2205
2205
|
console.log.apply(console, arguments)
|
|
2206
2206
|
}
|
|
2207
2207
|
function statelog (key, color, icon, message) {
|
|
2208
|
+
if (bus.honking_colors === false)
|
|
2209
|
+
color = ''
|
|
2208
2210
|
if (honking_at(key))
|
|
2209
2211
|
indented_log(color + icon + ' ' + message + normal)
|
|
2210
2212
|
}
|