How can I use D to develop web application?
mta`chrono
chrono at mta-international.net
Sun Sep 25 02:11:59 PDT 2011
> Thank you very much. I think the cgi module is lower effecient. I found
> fcgi(http://www.dsource.org/projects/fastcgi4d) and
> mango(http://www.dsource.org/projects/mango) which support servlet. But they don't
> support D2, anyone else can merge them to D2?
>
> zsxxsz
I've some D2 code working with fastcgi. It accepts some web request,
makes live a screenshot of my environment, converts it to png, and sends
it back.
basically it's an own implementation of the fastcgi protocol. but I
think I haven't yet covered all of it. But it's sufficant for me....
/*
* main
*/
int main(char[][] args)
{
// init
FcgiApplication fastcgi = new FcgiApplication();
// listen
fastcgi.listen(8080);
// redirection
fastcgi.accept("/redirect.html", (FcgiRequest request)
{
request.redirect("http://www.google.de");
});
// dir
fastcgi.accept("/users.html", (FcgiRequest request)
{
request.send("<a href=\"/\">back</a>");
request.send("directory!");
string dir = std.process.shell("ls /etc");
request.send("<pre>" ~ dir ~ "</pre>");
});
// counter
int counter = 0;
fastcgi.accept("/lukas.html", (FcgiRequest request)
{
counter++;
request.send("hello world!" ~ to!string(counter));
});
// show all variables
fastcgi.accept((FcgiRequest request)
{
request.send("<table>");
foreach(key, value; request.params) {
string html = std.string.format("<tr><td>%s</td <td>%s</td></tr>",
key, value);
request.send(html);
}
request.send("</table>");
});
// wait until forever
return fastcgi.exec();
}
More information about the Digitalmars-d
mailing list