mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
better main and args handling
This commit is contained in:
parent
75045549a6
commit
e84c864a10
1 changed files with 20 additions and 3 deletions
|
@ -100,11 +100,28 @@ void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared static this()
|
void main(string[] argv)
|
||||||
{
|
{
|
||||||
|
import std.getopt;
|
||||||
|
import vibe.core.core : runEventLoop, lowerPrivileges;
|
||||||
|
|
||||||
|
ushort port = 8080;
|
||||||
|
string host = "127.0.0.1";
|
||||||
|
auto rslt = getopt(argv,
|
||||||
|
"port|p", "Bind to this port.", &port,
|
||||||
|
"host|H", "Listen to this interface.", &host,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rslt.helpWanted){
|
||||||
|
defaultGetoptPrinter("Some information about the program.",
|
||||||
|
rslt.options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto settings = new HTTPServerSettings;
|
auto settings = new HTTPServerSettings;
|
||||||
settings.port = 8080;
|
settings.port = port;
|
||||||
settings.bindAddresses = ["::1", "127.0.0.1"];
|
settings.bindAddresses = [host];
|
||||||
|
|
||||||
listenHTTP(settings, &handleRequest);
|
listenHTTP(settings, &handleRequest);
|
||||||
|
lowerPrivileges();
|
||||||
|
runEventLoop();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue