This repository was archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (48 loc) · 1.58 KB
/
index.js
File metadata and controls
60 lines (48 loc) · 1.58 KB
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
const makeDebug = require('debug');
const Proto = require('uberproto');
const socket = require('feathers-socket-commons');
const Primus = require('primus');
const Emitter = require('primus-emitter');
const debug = makeDebug('feathers-primus');
module.exports = function (config, configurer) {
return function () {
const app = this;
app.configure(socket('primus'));
// Monkey patch app.setup(server)
Proto.mixin({
setup (server) {
debug('Setting up Primus');
let primus = this.primus;
if (!primus) {
primus = this.primus = new Primus(server, config);
primus.plugin('emitter', Emitter);
primus.use('feathers', function (req, res, next) {
req.feathers = { provider: 'primus' };
next();
}, 0);
}
if (typeof configurer === 'function') {
debug('Calling Primus configuration function');
configurer.call(this, primus);
}
this._socketInfo = {
method: 'send',
connection () {
return primus;
},
clients () {
return primus;
},
params (spark) {
return spark.request.feathers;
}
};
// In Feathers it is easy to hit the standard Node warning limit
// of event listeners (e.g. by registering 10 services).
// So we set it to a higher number. 64 should be enough for everyone.
this._socketInfo.connection().setMaxListeners(64);
return this._super.apply(this, arguments);
}
}, app);
};
};