You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/03/24 20:25:02 UTC

git commit: CB-6030 - Automatically increment port for serve when default is in use

Repository: cordova-cli
Updated Branches:
  refs/heads/master 07181e4ee -> bd108d59b


CB-6030 - Automatically increment port for serve when default is in use


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/bd108d59
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/bd108d59
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/bd108d59

Branch: refs/heads/master
Commit: bd108d59b6daff5803a27c67c38fbcb57d459734
Parents: 07181e4
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Thu Feb 13 09:55:59 2014 -0500
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Mon Mar 24 15:23:48 2014 -0400

----------------------------------------------------------------------
 src/serve.js | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bd108d59/src/serve.js
----------------------------------------------------------------------
diff --git a/src/serve.js b/src/serve.js
index c941806..bd17fa3 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -155,10 +155,16 @@ function launchServer(projectRoot, port) {
                 return do404();
             }
         });
-
-    }).listen(port, undefined, undefined, function (listeningEvent) {
+    }).on('listening', function () {
         console.log("Static file server running on port " + port + " (i.e. http://localhost:" + port + ")\nCTRL + C to shut down");
-    });
+    }).on('error', function (e) {
+        if (e && e.toString().indexOf('EADDRINUSE') !== -1) {
+            port++;
+            server.listen(port);
+        } else {
+            console.log("An error occured starting static file server: " + e);
+        }
+    }).listen(port);
     return server;
 }