-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgrasshopper.js
87 lines (80 loc) · 2.84 KB
/
grasshopper.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
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
'use strict';
var q = require('q'),
grasshopper = {
init: function(options){
this.config.init(options);
this.db = require('./db')();
return this;
},
/**
* Property to return the current loaded configuration
* @type {*}
*/
config: require('./config'),
/**
* Raw database layer
* @type {exports}
*/
db: {},
/**
* Expose the events that are taking place in grasshopper core.
*/
event: require('./event'),
/**
* Expose the available roles in the system.
*/
roles: require('./security/roles'),
/**
* Expose a function that you can use to authenticate and get a token to use for authenticated calls.
*/
auth: require('./security/auth'),
/**
* Exposed function to get the current version of the grasshopper-core
*/
version: require('./utils/version'),
/**
* Exposed function to get the google oAuth2 URL
*/
googleAuthUrl: require('./utils/googleAuthUrl'),
/**
* Expose a function to aid in the building of queries against db
* @type {{queryBuilder: exports}}
*/
utilities: {
queryBuilder : require('./utils/queryBuilder')
},
close: function() {
return require('./db/' + this.config.db.type + '/close')(this.db);
},
/**
* The grasshopper request function will return back an object that can execute calls to the system.
* If you are making an authenticated call then you should send in your token. If you are making a
* public call then don't pass in an argument.
* @param token
* @returns {{users: *, tokens: *, content: *, contentTypes: *, nodes: *}}
*/
request: function(token){
return {
users: require('./runners/users')(token),
tokens: require('./runners/tokens')(token),
content: require('./runners/content')(token),
contentTypes: require('./runners/contentTypes')(token),
nodes: require('./runners/nodes')(token),
assets: require('./runners/assets')(token),
system: require('./runners/system')(token)
};
}
};
q.longStackSupport = true;
module.exports = grasshopper;
process.on('SIGINT', shutdown);
process.on('SIGUSR2', shutdown);
function shutdown(){ //Issue system/shutdown on SIGINT & SIGUSR2
var coordinator = require('./runners/coordinator'),
middleware = require('./middleware');
coordinator.use('system.shutdown', [
middleware.event('shutdown'),
middleware.system.shutdown
]);
coordinator.handle('system.shutdown', [], grasshopper);
}