-
Notifications
You must be signed in to change notification settings - Fork 197
/
server.js
40 lines (32 loc) · 1.2 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
var configure=require("./app").configure;
var _ = require('underscore');
var mqtt = require("mqtt");
var coap = require("coap");
var WebSocketServer = require('ws').Server;
var config = require('config');
start = function (opts, callback) {
var app = configure();
app.listen(config.get('port.http'), function () {
console.log("http server run on port %d", config.get('port.http'));
});
if (_.include(app.config.get('modules'), 'websocket')) {
var webSocketServer = new WebSocketServer({port: config.get('port.websocket')});
app.websocket(webSocketServer);
console.log("websocket server listening on port %d", config.get('port.websocket'));
}
if (_.include(app.config.get('modules'), 'coap')) {
coap.createServer(app.coap).listen(config.get('port.coap'), function () {
console.log("coap server listening on port %d", config.get('port.coap'));
});
}
if (_.include(app.config.get('modules'), 'mqtt')) {
mqtt.MqttServer(app.mqtt).listen(config.get('port.mqtt'), function () {
console.log("mqtt server listening on port %d", config.get('port.mqtt'));
});
}
return app;
};
if (require.main.filename === __filename) {
start();
}
module.exports.start = start;