-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.bak
115 lines (93 loc) · 2.66 KB
/
serve.bak
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
var Phant = require('phant'),
dotenv = require('dotenv').load(),
path = require('path'),
HttpManager = require('phant-manager-sparkfun'),
Keychain = require('phant-keychain-hex'),
Meta = require('phant-meta-mongodb'),
Storage = require('phant-stream-mongodb'),
MqttIn = require('phant-input-mqtt'),
MqttOut = require('phant-output-mqtt'),
Throttler = require('phant-throttler-redis'),
Mailer = require('phant-notify-email'),
redis = require('redis'),
app = Phant();
var mailer = Mailer({
from: 'data.sparkfun.com <data@sparkfun.com>',
subject: 'New data.sparkfun.com Stream: ',
host: 'https://data.sparkfun.com'
});
mailer.useSendmail();
var keys = Keychain({
publicSalt: process.env.PHANT_PUBLIC_SALT || 'public salt',
privateSalt: process.env.PHANT_PRIVATE_SALT || 'private salt',
deleteSalt: process.env.PHANT_DELETE_SALT || 'delete salt'
});
var mongo = Meta({
url: process.env.PHANT_MONGO_URL || 'mongodb://localhost/phant'
});
var stream = Storage({
cap: process.env.PHANT_CAP || 50 * 1024 * 1024, // 50mb
url: process.env.PHANT_MONGO_URL || 'mongodb://localhost/phant'
});
var validator = Phant.Validator({
metadata: mongo
});
var httpOutput = Phant.HttpOutput({
validator: validator,
storage: stream,
keychain: keys
});
var throttler = Throttler({
host: process.env.PHANT_REDIS_HOST || 'localhost',
port: process.env.PHANT_REDIS_PORT || 6379,
limit: 300
});
var httpInput = Phant.HttpInput({
throttler: throttler,
validator: validator,
keychain: keys
});
var httpManager = HttpManager({
metadata: mongo,
keychain: keys,
validator: validator,
notifiers: [mailer]
});
// start listening for connections
Phant.HttpServer.listen(process.env.PHANT_PORT || 8080);
// attach input to http server
Phant.HttpServer.use(httpInput);
// attach manager to http server
Phant.HttpServer.use(httpManager);
// register manager with phant
app.registerManager(httpManager);
// attach output to http server
Phant.HttpServer.use(httpOutput);
// register input with phant
app.registerInput(httpInput);
app.registerOutput(stream);
app.registerOutput(httpOutput);
// mqtt out will use the same config
var mqttIn = MqttIn({
throttler: throttler,
validator: validator,
keychain: keys,
port: 1883,
backend: {
type: 'redis',
redis: require('redis'),
port: process.env.PHANT_REDIS_PORT || 6379,
host: process.env.PHANT_REDIS_HOST || 'localhost',
return_buffers: true
}
});
// enable mqtt over websockets
mqttIn.server.attachHttpServer(Phant.HttpServer.server);
app.registerInput(mqttIn);
app.registerOutput(
MqttOut({
validator: validator,
keychain: keys
})
);