Am 10.06.2015 um 11:52 schrieb Suliman:
Why don't you want to use
serveStaticFile
if youwant to do exactly what it does ?Because I do not understand why I can't do serveStaticFiles in handler ("index" in my case) and must do serveStaticFiles inside get.
I am trying to understand it, because if I would not understand logic of this case I would have problems with more complicated code.
You could also do this:
static this() {
// ...
router.get("/", &index);
router.get("/index.html", &serveIndex);
}
void serveIndex(HTTPServerRequest req, HTTPServerResponse res)
{
static HTTPServerRequestDelegateS file_server;
if (!file_server) file_server = serveStaticFile("/public/index.html");
file_server(req, res);
}
There is a private sendFile
method in vibe.http.fileserver
that we
could also make public to better support this kind of use case. Do you
have a particular reason why directly using serveStaticFile(s)
with router.get()
is not ideal, or do you just want to understand the logic
behind it?