From 8de33e0a3a30996b5eee00b8e319b6a4b424e0a7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 1 Jun 2011 15:06:03 -0500 Subject: [PATCH] Rebuild JS --- lib/client.js | 32 ++++++++----------------------- lib/pool.js | 20 ++++++------------- lib/process.js | 52 +++++++++++++++++++------------------------------- lib/server.js | 18 +++-------------- lib/util.js | 2 +- 5 files changed, 38 insertions(+), 86 deletions(-) diff --git a/lib/client.js b/lib/client.js index fe411af..416bc52 100644 --- a/lib/client.js +++ b/lib/client.js @@ -16,6 +16,7 @@ Stream = require('stream').Stream; debug = require('./util').debug; exports.Client = Client = (function() { + __extends(Client, Socket); function Client() { this.proxy = __bind(this.proxy, this);; var self; Client.__super__.constructor.apply(this, arguments); @@ -37,7 +38,6 @@ }); this._initResponseParser(); } - __extends(Client, Socket); Client.prototype._initResponseParser = function() { var nsStream, self; self = this; @@ -94,7 +94,7 @@ request = (function(func, args, ctor) { ctor.prototype = func.prototype; var child = new ctor, result = func.apply(child, args); - return typeof result === "object" ? result : child; + return typeof result == "object" ? result : child; })(ClientRequest, args, function() {}); this._outgoing.push(request); this._processRequest(); @@ -103,16 +103,8 @@ Client.prototype.proxy = function(serverRequest, serverResponse, next) { var clientRequest, metaVariables, _ref, _ref2, _ref3; metaVariables = (_ref = serverRequest.proxyMetaVariables) != null ? _ref : {}; - if ((_ref2 = metaVariables['REMOTE_ADDR']) != null) { - _ref2; - } else { - metaVariables['REMOTE_ADDR'] = "" + serverRequest.connection.remoteAddress; - }; - if ((_ref3 = metaVariables['REMOTE_PORT']) != null) { - _ref3; - } else { - metaVariables['REMOTE_PORT'] = "" + serverRequest.connection.remotePort; - }; + (_ref2 = metaVariables['REMOTE_ADDR']) != null ? _ref2 : metaVariables['REMOTE_ADDR'] = "" + serverRequest.connection.remoteAddress; + (_ref3 = metaVariables['REMOTE_PORT']) != null ? _ref3 : metaVariables['REMOTE_PORT'] = "" + serverRequest.connection.remotePort; clientRequest = this.request(serverRequest.method, serverRequest.url, serverRequest.headers, metaVariables); serverRequest.on('data', function(data) { return clientRequest.write(data); @@ -141,6 +133,7 @@ }; END_OF_FILE = ns.nsWrite(""); exports.ClientRequest = ClientRequest = (function() { + __extends(ClientRequest, Stream); function ClientRequest(method, path, headers, metaVariables) { this.method = method; this.path = path; @@ -150,7 +143,6 @@ this._parseEnv(headers, metaVariables); this.write(JSON.stringify(this.env)); } - __extends(ClientRequest, Stream); ClientRequest.prototype._parseEnv = function(headers, metaVariables) { var host, key, parts, pathname, query, value, _base, _base2, _ref, _ref2, _ref3, _results; this.env = {}; @@ -166,16 +158,8 @@ this.env['SERVER_NAME'] = parts[0]; this.env['SERVER_PORT'] = parts[1]; } - if ((_ref2 = (_base = this.env)['SERVER_NAME']) != null) { - _ref2; - } else { - _base['SERVER_NAME'] = "localhost"; - }; - if ((_ref3 = (_base2 = this.env)['SERVER_PORT']) != null) { - _ref3; - } else { - _base2['SERVER_PORT'] = "80"; - }; + (_ref2 = (_base = this.env)['SERVER_NAME']) != null ? _ref2 : _base['SERVER_NAME'] = "localhost"; + (_ref3 = (_base2 = this.env)['SERVER_PORT']) != null ? _ref3 : _base2['SERVER_PORT'] = "80"; for (key in headers) { value = headers[key]; key = key.toUpperCase().replace(/-/g, '_'); @@ -243,6 +227,7 @@ return ClientRequest; })(); exports.ClientResponse = ClientResponse = (function() { + __extends(ClientResponse, Stream); function ClientResponse(socket, request) { this.socket = socket; this.request = request; @@ -256,7 +241,6 @@ this.headers = null; this._buffer = null; } - __extends(ClientResponse, Stream); ClientResponse.prototype._receiveData = function(data) { var error, exception, k, rawHeaders, v, vs; debug("received " + data.length + " bytes"); diff --git a/lib/pool.js b/lib/pool.js index 68857ba..fd171d2 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -14,20 +14,13 @@ createProcess = require('./process').createProcess; isFunction = require('./util').isFunction; exports.Pool = Pool = (function() { + __extends(Pool, EventEmitter); function Pool(config, options) { var n, previousReadyWorkerCount, self, _ref, _ref2; this.config = config; this.proxy = __bind(this.proxy, this);; - if (options != null) { - options; - } else { - options = {}; - }; - if ((_ref = options.size) != null) { - _ref; - } else { - options.size = 1; - }; + options != null ? options : options = {}; + (_ref = options.size) != null ? _ref : options.size = 1; this.workers = []; this.round = 0; this.processOptions = { @@ -53,11 +46,10 @@ return self.emit('exit'); } }); - for (n = 1, _ref2 = options.size; 1 <= _ref2 ? n <= _ref2 : n >= _ref2; 1 <= _ref2 ? n++ : n--) { + for (n = 1, _ref2 = options.size; (1 <= _ref2 ? n <= _ref2 : n >= _ref2); (1 <= _ref2 ? n += 1 : n -= 1)) { this.increment(); } } - __extends(Pool, EventEmitter); Pool.prototype.__defineGetter__('runOnce', function() { return this.processOptions.runOnce; }); @@ -143,7 +135,7 @@ spawn = function(worker, callback) { return worker.spawn(callback); }; - return async.forEach(this.workers, spawn, typeof callback !== "undefined" && callback !== null ? callback : function() {}); + return async.forEach(this.workers, spawn, typeof callback != "undefined" && callback !== null ? callback : function() {}); }; Pool.prototype.terminate = function(callback) { var terminate; @@ -179,7 +171,7 @@ return (function(func, args, ctor) { ctor.prototype = func.prototype; var child = new ctor, result = func.apply(child, args); - return typeof result === "object" ? result : child; + return typeof result == "object" ? result : child; })(Pool, args, function() {}); }; AggregateStream = (function() { diff --git a/lib/process.js b/lib/process.js index e01ce36..8b6e648 100644 --- a/lib/process.js +++ b/lib/process.js @@ -20,20 +20,17 @@ packageLib = fs.realpathSync(__dirname); packageBin = fs.realpathSync("" + __dirname + "/../bin"); exports.Process = Process = (function() { + __extends(Process, EventEmitter); function Process(config, options) { - var raiseConfigError, _ref4, _ref5, _ref6; + var raiseConfigError, _ref, _ref2, _ref3; this.config = config; this.proxy = __bind(this.proxy, this);; this.id = Math.floor(Math.random() * 1000); - if (options != null) { - options; - } else { - options = {}; - }; - this.runOnce = (_ref4 = options.runOnce) != null ? _ref4 : false; + options != null ? options : options = {}; + this.runOnce = (_ref = options.runOnce) != null ? _ref : false; this.idle = options.idle; - this.cwd = (_ref5 = options.cwd) != null ? _ref5 : dirname(this.config); - this.env = (_ref6 = options.env) != null ? _ref6 : {}; + this.cwd = (_ref2 = options.cwd) != null ? _ref2 : dirname(this.config); + this.env = (_ref3 = options.env) != null ? _ref3 : {}; this.state = null; this._connectionQueue = []; this._activeConnection = null; @@ -50,7 +47,6 @@ raiseConfigError(); } } - __extends(Process, EventEmitter); Process.prototype.__defineGetter__('runOnce', function() { return this._runOnce; }); @@ -62,7 +58,7 @@ return this._runOnce = value; }); Process.prototype.spawn = function(callback) { - var env, key, logData, onSpawn, out, value, _ref4, _ref5; + var env, key, logData, onSpawn, out, value, _ref, _ref2; if (this.state) { return; } @@ -79,14 +75,14 @@ this.changeState('spawning'); this.sockPath = "" + (tmpFile()) + ".sock"; env = {}; - _ref4 = process.env; - for (key in _ref4) { - value = _ref4[key]; + _ref = process.env; + for (key in _ref) { + value = _ref[key]; env[key] = value; } - _ref5 = this.env; - for (key in _ref5) { - value = _ref5[key]; + _ref2 = this.env; + for (key in _ref2) { + value = _ref2[key]; env[key] = value; } env['PATH'] = "" + packageBin + ":" + env['PATH']; @@ -134,11 +130,7 @@ this.stderr = this.child.stderr; out = null; logData = function(data) { - if (out != null) { - out; - } else { - out = ""; - }; + out != null ? out : out = ""; return out += data.toString(); }; this.stdout.on('data', logData); @@ -230,15 +222,11 @@ debug("proxy " + req.method + " " + req.url + " to #" + this.id); resume = pause(req); return this.createConnection(function(err, connection) { - var _ref4; + var _ref; if (err) { next(err); } else { - if ((_ref4 = req.proxyMetaVariables) != null) { - _ref4; - } else { - req.proxyMetaVariables = {}; - }; + (_ref = req.proxyMetaVariables) != null ? _ref : req.proxyMetaVariables = {}; req.proxyMetaVariables['rack.run_once'] = this.runOnce; connection.proxy(req, res, next); } @@ -257,7 +245,7 @@ return this.heartbeat.destroy(); } } else { - return typeof callback === "function" ? callback() : void 0; + return typeof callback == "function" ? callback() : void 0; } }; Process.prototype.terminate = function(callback) { @@ -282,7 +270,7 @@ return clearTimeout(timeout); }); } else { - return typeof callback === "function" ? callback() : void 0; + return typeof callback == "function" ? callback() : void 0; } }; Process.prototype.quit = function(callback) { @@ -306,7 +294,7 @@ return clearTimeout(timeout); }); } else { - return typeof callback === "function" ? callback() : void 0; + return typeof callback == "function" ? callback() : void 0; } }; Process.prototype.restart = function(callback) { @@ -323,7 +311,7 @@ return (function(func, args, ctor) { ctor.prototype = func.prototype; var child = new ctor, result = func.apply(child, args); - return typeof result === "object" ? result : child; + return typeof result == "object" ? result : child; })(Process, args, function() {}); }; tmpFile = function() { diff --git a/lib/server.js b/lib/server.js index c950bb9..33f57e2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -4,21 +4,9 @@ createPool = require('./pool').createPool; exports.createServer = function(config, options) { var pool, server, _ref, _ref2; - if (options != null) { - options; - } else { - options = {}; - }; - if ((_ref = options.size) != null) { - _ref; - } else { - options.size = 3; - }; - if ((_ref2 = options.idle) != null) { - _ref2; - } else { - options.idle = 15 * 60 * 1000; - }; + options != null ? options : options = {}; + (_ref = options.size) != null ? _ref : options.size = 3; + (_ref2 = options.idle) != null ? _ref2 : options.idle = 15 * 60 * 1000; pool = createPool(config, options); server = createServer(pool.proxy); server.on('close', function() { diff --git a/lib/util.js b/lib/util.js index b42c8fe..f728758 100644 --- a/lib/util.js +++ b/lib/util.js @@ -61,6 +61,7 @@ }; }; exports.LineBuffer = LineBuffer = (function() { + __extends(LineBuffer, Stream); function LineBuffer(stream) { var self; this.stream = stream; @@ -78,7 +79,6 @@ return self.end.apply(self, args); }); } - __extends(LineBuffer, Stream); LineBuffer.prototype.write = function(chunk) { var index, line, _results; this._buffer += chunk;