feat(bot): listen on multiple addresses, for v4/v6

This commit is contained in:
alyssa 2025-04-27 19:09:44 +00:00
parent f7b594e415
commit 3d0eb562bf

View file

@ -25,15 +25,23 @@ public class HttpListenerService
public void Start(string host)
{
var server = new WebserverLite(new WebserverSettings(host, 5002), DefaultRoute);
var hosts = new[] { host };
if (host == "allv4v6")
{
hosts = new[] { "[::]", "0.0.0.0" };
}
foreach (var h in hosts)
{
var server = new WebserverLite(new WebserverSettings(h, 5002), DefaultRoute);
server.Routes.PreAuthentication.Static.Add(WatsonWebserver.Core.HttpMethod.GET, "/runtime_config", RuntimeConfigGet);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.POST, "/runtime_config/{key}", RuntimeConfigSet);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.DELETE, "/runtime_config/{key}", RuntimeConfigDelete);
server.Routes.PreAuthentication.Static.Add(WatsonWebserver.Core.HttpMethod.GET, "/runtime_config", RuntimeConfigGet);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.POST, "/runtime_config/{key}", RuntimeConfigSet);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.DELETE, "/runtime_config/{key}", RuntimeConfigDelete);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.POST, "/events/{shard_id}", GatewayEvent);
server.Routes.PreAuthentication.Parameter.Add(WatsonWebserver.Core.HttpMethod.POST, "/events/{shard_id}", GatewayEvent);
server.Start();
server.Start();
}
}
private async Task DefaultRoute(HttpContextBase ctx)