-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (48 loc) · 1.87 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
module.exports = function (sails) {
var loader = require('sails-util-mvcsloader')(sails);
// Declare a var that will act as a reference to this hook.
var hook;
return {
defaults: {
adminx: {
authEnabled: true,
dataAuthToken: null
},
policies: {
AdminXController: {
'*': ['adminxHeaderAuth']
},
}
},
configure: function () {
// Load policies under ./api/policies and config under ./config
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-config--policies
loader.configure({
policies: __dirname + '/api/policies',// Path to the policies to load
config: __dirname + '/config' // Path to the config to load
});
//SAILS BUG: It seems sails OPTIONS requests don't return the headers configured on a per-route basis
//SOLUTION: Modify sails.config.headers on the fly to add ours
var headerName = 'adminx-data-auth-token';
if (sails.config.cors.headers.indexOf(headerName) === -1) {
sails.config.cors.headers += ',' + headerName;
}
},
initialize: function (cb) {
// Assign this hook object to the `hook` var.
// This allows us to add/modify values that users of the hook can retrieve.
hook = this;
//TODO: check if sails has enabled an ORM or throw an Error/Warning
// Load controllers under ./api/controllers and services under ./services
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-models--controllers--services
loader.inject({
controllers: __dirname + '/api/controllers', // Path to the controllers to load
services: __dirname + '/api/services' // Path to the services to load
}, function(err) {
// Signal that initialization of this hook is complete
// by calling the callback.
return cb(err);
});
}
};
};