vibed: how to use pure HTML instead of template engine?

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 02:57:43 PDT 2015


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.
}


More information about the Digitalmars-d-learn mailing list