Permalink
Browse files

Made port optional in gh.serve() and made it return the http.Server t…

…hat was created.
  • Loading branch information...
1 parent 500a35e commit 5117d67de408dc513c41314d3f507734f55612b1 @cskr committed Nov 19, 2010
Showing with 10 additions and 10 deletions.
  1. +10 −10 grasshopper/lib/routes.js
@@ -63,11 +63,11 @@ exports.api.secureDel = function(path, controller) {
}
exports.api.serve = function(port, hostname, callback) {
- startServer(routes, port, undefined, hostname, callback);
+ return startServer(routes, port, undefined, hostname, callback);
};
exports.api.serveSecure = function(port, credentials, hostname, callback) {
- startServer(secureRoutes, port, credentials, hostname, callback);
+ return startServer(secureRoutes, port, credentials, hostname, callback);
};
exports.api.stop = function() {
@@ -85,10 +85,6 @@ exports.api.getSecureController = function(method, path) {
return secureRoutes[method + ':' + path];
};
-exports.api.servers = function() {
- return servers;
-};
-
function redirectSecure() {
var hostHeader = this.request.headers['host'];
var redirectHost = hostHeader;
@@ -121,8 +117,12 @@ function startServer(routes, port, credentials, hostname, callback) {
});
servers.push(server);
- server.listen(port, hostname, function() {
- console.log('Hopping at port: ' + port + '. Use Ctrl+C to stop.');
- if(callback) callback();
- });
+ if(typeof port == 'number') {
+ server.listen(port, hostname, function() {
+ console.log('Hopping at port: ' + port + '. Use Ctrl+C to stop.');
+ if(callback) callback();
+ });
+ }
+
+ return server;
}

0 comments on commit 5117d67

Please sign in to comment.