Port specified by command line argument

This commit is contained in:
Elijah 2024-07-02 20:17:03 -04:00
parent 4edd94b302
commit 1288682766

View file

@ -12,6 +12,12 @@ namespace SAPIServer
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
if (args.Length < 1 || !ushort.TryParse(args[0], out var port))
{
Console.Error.WriteLine("Usage: SAPIServer.exe <port>");
Environment.Exit(1);
return;
}
var http = new HTTPServer(); var http = new HTTPServer();
http.Get("/api/voices", ctx => http.Get("/api/voices", ctx =>
{ {
@ -61,7 +67,8 @@ namespace SAPIServer
return ms.ToArray(); return ms.ToArray();
} }
}); });
http.Listen(8080); Console.WriteLine($"[{ DateTime.Now:u}] Starting HTTP server on port {port}");
http.Listen(port);
} }
} }
} }