You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is staticTemplate for serving one .dt file, but functionality for routing to specific other static file is missing. Only multiple files can be routed with serveStaticFiles but they must correspond to physical layout. I implemented simple function (in text below) for serving static file with router. It is extremely basic, and repurposing serveStaticFiles for this functionality would be better. (but this works for very simple use case)
static this()
{
auto router = new UrlRouter;
router
.get("/", staticFile("views\\index.html", "text/html; charset=UTF-8"))
.get("*", serveStaticFiles("./public/"));
auto settings = new HttpServerSettings;
settings.port = 777;
listenHttp(settings, router);
}
HTTPServerRequestDelegate staticFile(string path, string contentType)
{
return (HTTPServerRequest req, HTTPServerResponse res){
auto fil = openFile(path);
scope(exit) fil.close();
res.contentType = contentType;
res.bodyWriter.write(fil);
};
}
The text was updated successfully, but these errors were encountered:
Currently there is staticTemplate for serving one .dt file, but functionality for routing to specific other static file is missing. Only multiple files can be routed with serveStaticFiles but they must correspond to physical layout. I implemented simple function (in text below) for serving static file with router. It is extremely basic, and repurposing serveStaticFiles for this functionality would be better. (but this works for very simple use case)
The text was updated successfully, but these errors were encountered: