import vibe.d;
import std.regex;
import std.array : appender;
static reg = ctRegex!"^/greeting/([a-z]+)$";
void main()
{
setupWorkerThreads(logicalProcessorCount);
runWorkerTaskDist(&runServer);
runApplication();
}
void runServer()
{
auto settings = new HTTPServerSettings;
settings.options |= HTTPServerOption.reusePort;
settings.port = 3000;
settings.serverString = null;
listenHTTP(settings, &handleRequest);
}
void handleRequest(HTTPServerRequest req,
HTTPServerResponse res)
{
switch(req.path)
{
case "/": res.writeBody("Hello World", "text/plain");
break;
default:
auto m = matchFirst(req.path, reg);
string message = "Hello, ";
auto app = appender(message);
app.reserve(32);
app ~= m[1];
res.writeBody(app.data, "text/plain");
}
}