-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (44 loc) · 1.25 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var bus = require('statebus')()
var app = require('express')()
// Create the HTTP server
require('http')
.createServer(app)
.listen(3007, () => console.log('listening on 3007'))
// Setup the statebus!
bus.honk = true // Print handy debugging output
bus.libs.file_store() // Persist state onto disk
bus.state['@toomim'] = 3
// // Install a timer.
// //
// // Or you could use
// // bus.libs.time()
// //
// var timeout
// bus('time', {
// get: (t) => {
// var f = () => t.done(Date.now())
// timeout = setInterval(f, 1000)
// f()
// },
// forget: () => clearTimeout(timeout) // Unsubscribe
// })
// // Let's program some state!
// bus('what-now', {
// get: () => bus.state.time,
// set: (val) => bus.state.yeep = val
// })
// // Here's a value that's always 2+ another number
// bus.state.counter = 0
// bus('two-plus', {
// get: () => bus.state.counter + 2,
// set: (val) => bus.state.counter = val - 2
// })
// Serve other state from statebus
app.use(bus.libs.http_in)
// Other libs you might like:
// bus.libs.sqlite_store()
// bus.libs.pg_store()
// bus.libs.firebase_store()
// bus.libs.sqlite_query_server()
// bus.libs.sqlite_table_server()
// bus.libs.serve_email()