forked from balderdashy/sails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sails.js
120 lines (92 loc) · 3.68 KB
/
Sails.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Module dependencies.
*/
var events = require('events');
var _ = require('lodash');
var util = require('util');
var loadSails = require('./load');
var mixinAfter = require('./private/after');
var __Router = require('../router');
var CaptainsLog = require('captains-log');
/**
* Construct a Sails (app) instance.
*
* @constructor
*/
function Sails() {
// Inherit methods from EventEmitter
events.EventEmitter.call(this);
// Remove memory-leak warning about max listeners
// See: http://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n
this.setMaxListeners(0);
// Keep track of spawned child processes
this.childProcesses = [];
// Ensure CaptainsLog exists
this.log = CaptainsLog();
// Build a Router instance (which will attach itself to the sails object)
__Router(this);
// Mixin `load()` method to load the pieces
// of a Sails app
this.load = loadSails(this);
// Mixin support for `Sails.prototype.after()`
mixinAfter(this);
// Bind `this` context for all `Sails.prototype.*` methods
this.load = _.bind(this.load, this);
this.request = _.bind(this.request, this);
this.lift = _.bind(this.lift, this);
this.lower = _.bind(this.lower, this);
this.getBaseurl = _.bind(this.getBaseurl, this);
this.initialize = _.bind(this.initialize, this);
this.exposeGlobals = _.bind(this.exposeGlobals, this);
this.runBootstrap = _.bind(this.runBootstrap, this);
this.getHost = _.bind(this.getHost, this);
this.isLocalSailsValid = _.bind(this.isLocalSailsValid, this);
this.isSailsAppSync = _.bind(this.isSailsAppSync, this);
this.inspect = _.bind(this.inspect, this);
this.toString = _.bind(this.toString, this);
this.toJSON = _.bind(this.toJSON, this);
this.all = _.bind(this.all, this);
this.get = _.bind(this.get, this);
this.post = _.bind(this.post, this);
this.put = _.bind(this.put, this);
this['delete'] = _.bind(this['delete'], this);
}
// Extend from EventEmitter to allow hooks to listen to stuff
util.inherits(Sails, events.EventEmitter);
// Public methods
////////////////////////////////////////////////////////
Sails.prototype.lift = require('./lift');
Sails.prototype.lower = require('./lower');
Sails.prototype.getBaseurl = require('./getBaseurl');
Sails.prototype.getBaseURL = Sails.prototype.getBaseurl;
Sails.prototype.getBaseUrl = Sails.prototype.getBaseurl;
Sails.prototype.request = require('./request');
// Expose Express-esque synonyms for low-level usage of router
var _routerBindWrapper = function (path, action) {
this.router.bind(path, action);
return this;
};
Sails.prototype.all = _routerBindWrapper;
Sails.prototype.get = _routerBindWrapper;
Sails.prototype.post = _routerBindWrapper;
Sails.prototype.put = _routerBindWrapper;
Sails.prototype.del = Sails.prototype['delete'] = _routerBindWrapper;
// Private methods:
////////////////////////////////////////////////////////
Sails.prototype.initialize = require('./private/initialize');
Sails.prototype.exposeGlobals = require('./private/exposeGlobals');
Sails.prototype.runBootstrap = require('./private/bootstrap');
Sails.prototype.getHost = require('./private/getHost');
Sails.prototype.isLocalSailsValid = require('./private/isLocalSailsValid');
Sails.prototype.isSailsAppSync = require('./private/isSailsAppSync');
// Presentation
Sails.prototype.inspect = require('./private/inspect');
Sails.prototype.toString = require('./private/toString');
Sails.prototype.toJSON = require('./private/toJSON');
// Utilities
// Includes lodash, node's `util`, and a few additional
// static helper methods.
// (may be deprecated in a future release)
Sails.prototype.util = require('sails-util');
// Expose Sails constructor
module.exports = Sails;