-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
95 lines (76 loc) · 1.64 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
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
/*!
* Express - Contrib - configure
* Copyright(c) 2010 TJ Holowaychuk <[email protected]>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var express = require('express')
, HTTPServer = express.HTTPServer
, HTTPSServer = express.HTTPSServer;
// Proxy listen
var listen = HTTPServer.prototype.listen;
/**
* Proxy listen() to provide async support.
*
* @api public
*/
exports.listen = function(){
if (this.__config) {
this.__listen = arguments;
} else {
listen.apply(this, arguments);
}
};
// Proxy listenFD
var listenFD = HTTPServer.prototype.listenFD;
/**
* Proxy listen() to provide async support.
*
* @api public
*/
exports.listenFD = function(){
if (this.__config) {
this.__listenFD = arguments;
} else {
listenFD.apply(this, arguments);
}
};
// Proxy configure
var configure = HTTPServer.prototype.configure;
/**
* Proxy configure() to provide async support.
*
* @api public
*/
exports.configure = function(env, fn){
var self = this;
this.__config = this.__config || 0
if (typeof env === 'function') {
fn = env, env = 'all';
}
if ('all' == env || env == this.settings.env) {
if (fn.length) {
++this.__config;
fn.call(this, function(err){
if (err) throw err;
if (!--self.__config) {
if (self.__listen) {
listen.apply(self, self.__listen);
} else if (self.__listenFD) {
listenFD.apply(self, self.__listenFD);
}
}
});
} else {
fn.call(this);
}
}
return this;
};
// merge
for (var key in exports) {
HTTPServer.prototype[key] =
HTTPSServer.prototype[key] = exports[key];
}