-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (51 loc) · 1.35 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
59
60
61
62
63
64
65
66
var Server = require('./lib/server');
var proto = require('./lib/application');
var req = require('./lib/request');
var res = require('./lib/response');
var mixin = require('merge-descriptors');
/**
* Creates a new hoagie application.
* @returns {Object}
*/
exports = module.exports = function hoagie() {
function app(req, res, next) {
app.handle(req, res, next);
}
mixin(app, proto, false);
app.request = { app: app, __proto__: req };
app.response = { app: app, __proto__: res };
app.init();
app.run = function(argv) {
return hoagie.createServer(app).run(argv, process.stdin, process.stdout);
};
return app;
};
/**
* Alias for `process.argv.slice(2)`, which is the
* argument vector minus the environment and program.
* @returns {Array}
*/
exports.__defineGetter__('argv', function() {
return process.argv.slice(2);
});
/**
* Creates a new hoagie server with `handler` as the request
* handler. Applications are essentially complex `handler`
* functions.
* @param {Function} handler
* @returns {Object}
*/
exports.createServer = function(handler) {
return new Server(handler);
};
/**
* Router
*/
exports.Router = require('./lib/router');
exports.request = req;
exports.response = res;
/**
* Middleware
*/
exports.help = require('./lib/middleware/help');
exports.completion = require('./lib/middleware/completion');