Print http-server message, allow auto port finding starting at 3000

This commit is contained in:
Joshua Granick
2023-05-20 11:05:47 -07:00
parent 9cec64b34a
commit a90915cb3f
2 changed files with 18 additions and 15 deletions

View File

@@ -85,7 +85,7 @@ class HTML5Helper
} }
} }
public static function launch(project:HXProject, path:String, port:Int = 3000):Void public static function launch(project:HXProject, path:String, port:Int = 0):Void
{ {
if (project.app.url != null && project.app.url != "") if (project.app.url != null && project.app.url != "")
{ {
@@ -124,27 +124,25 @@ class HTML5Helper
Sys.command("chmod", ["+x", node]); Sys.command("chmod", ["+x", node]);
} }
var args = [server, path, "-c-1", "--cors"];
if (project.targetFlags.exists("port")) if (project.targetFlags.exists("port"))
{ {
port = Std.parseInt(project.targetFlags.get("port")); port = Std.parseInt(project.targetFlags.get("port"));
} }
Log.info("", " - \x1b[1mStarting local web server:\x1b[0m http://localhost:" + port); if (port != 0)
/*Thread.create (function () {
Sys.sleep (0.5);
System.openURL ("http://localhost:" + port);
});*/
var args = [server, path, "-p", Std.string(port), "-c-1", "--cors"];
if (project.targetFlags.exists("nolaunch"))
{ {
Log.info("\x1b[1mStarting local web server:\x1b[0m http://localhost:" + port); args.push("-p");
args.push(Std.string(port));
Log.info("", "\x1b[1mStarting local web server:\x1b[0m http://localhost:" + port);
} }
else else
{
Log.info("", "\x1b[1mStarting local web server:\x1b[0m http://localhost:[3000*]");
}
if (!project.targetFlags.exists("nolaunch"))
{ {
args.push("-o"); args.push("-o");
} }

View File

@@ -80,8 +80,13 @@ else if (colors) {
}; };
} }
// CHANGE: Always show logger info
if (!logger) logger = {};
logger.info = console.log;
if (!port) { if (!port) {
portfinder.basePort = 8080; // CHANGE: Start finding ports beginning at port 3000
portfinder.basePort = 3000;
portfinder.getPort(function (err, port) { portfinder.getPort(function (err, port) {
if (err) { throw err; } if (err) { throw err; }
listen(port); listen(port);