Later you can have more sophisticated methods, e.g. if you want to handle query strings you could do something like this:

import vibe.d;

shared static this()
{

  auto settings = new HTTPServerSettings;
  settings.port = 8080;
  settings.bindAddresses = ["::1", "127.0.0.1"];

  auto router = new URLRouter;
  router.get("*", serveStaticFiles("./public/"));

  /* This is the new bit */
  router.any("*", &handleRequest);

  listenHTTP(settings, router);

  logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}

void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
  if (!req.query.length)
    return;
  auto request = req.query;
  // Do something fancy with the request
  // ...
  // Create a result
  string result;
  // ...
  // Return the result to the client
res.writeBody(cast(ubyte[])result); // The client will receive this.
}

Reply via email to