-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (49 loc) · 1.73 KB
/
index.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
/**
* Created by Jim on 7/10/16.
* Main Hook for Eureca.io
*/
var path = require('path');
var fs = require('fs');
var Eureca = require('eureca.io');
var camelCase = require('camel-case');
function checkDirectorySync(directory) {
try {
fs.statSync(directory);
} catch (e) {
fs.mkdirSync(directory);
}
}
module.exports = function eureca(sails) {
return {
defaults: {
__configKey__: {
prefix: 'eureca.io',
onConnect: function () {
},
onDisconnect: function () {
},
onMessage: function () {
},
onError: function () {
},
allow: []
}
},
configure: function () {
},
initialize: function (cb) {
var self = this;
checkDirectorySync(path.join(sails.config.appPath, 'api', 'eureca'))
self.server = new Eureca.Server({ prefix: sails.config[this.configKey].prefix, allow: sails.config[this.configKey].allow });
self.server.attach(sails.hooks.http.server);
fs.readdirSync(path.join(sails.config.appPath, 'api', 'eureca')).forEach(function (file) {
self.server.exports[camelCase(path.basename(file, '.js'))] = require(path.join(sails.config.appPath, 'api', 'eureca', file));
});
self.server.onConnect(sails.config[this.configKey].onConnect);
self.server.onDisconnect(sails.config[this.configKey].onDisconnect);
self.server.onMessage(sails.config[this.configKey].onMessage);
self.server.onError(sails.config[this.configKey].onError);
return cb();
}
};
};