On Wed, 06 Jan 2016 12:09:37 GMT, Martin Tschierschke wrote:

On Mon, 27 Jan 2014 20:03:03 +0100, Sönke Ludwig wrote:

Am 25.01.2014 08:41, schrieb Ty Overby:

Also, why is the form that I was using valid at all? Was it actually doing something that I wasn't detecting?

The problem is that the serveStaticFiles function, when it gets a
routed request like "/static/image.png", has no way to know that the
matching route looks like "/static/*" and it should drop the prefix. So
in this case it expects the file to be at "./static/static/image.png".

Did you meant "./public/static/image.png" ?

Yes, sorry for the confusion.

The example in the documentation assumes that all the static files are
placed directly in "/", so "/image.png" would be looked up in
"./public/image.png" - and for this case it should still be valid.

But there should definitely be a short example of using the advanced
settings version of serveStaticFiles, if not in the main
documentation, at least on the API page for serveStaticFiles.

Despite of being an old thread, I have run in the same problem, what about giving the following example:

router.get("/styles/*", serveStaticFiles("public/"));

while addressing the .css directly in diet

link(rel= 'stylesheet', type='text/css', href='/style/style.css`

Or additionaly about extending the allowed expressions with (*) Example:

router.get("/static/(*)", serveStaticFiles("public/"));`

So that only the matching part (*) of the path is passed to serveStaticFiles?

The use of the other "version" with:
auto fsettings = new HTTPFileServerSettings;<br>fsettings.serverPathPrefix = "/static";

is not nice at all.

The problem is that the router and the file server are completely distinct and there is no way for the file server to get this information.

However, an idea would be to add a separate function that is used like this: router.serveStaticFiles("/styles/", "public/styles/");

void serveStaticFiles(URLRouter router, string request_folder, string local_folder)
{
  auto settings = new HTTPFileServerSettings;
  settings.serverPathPrefix = request_folder;
  router.get(request_folder~"*", serveStaticFiles(local_folder, settings));
}

The only issue is to find a good place for it. It would be a bit of a pity to couple the two modules together, but if nothing else helps, letting vibe.http.fileserver import vibe.http.router might be acceptable. ... or it could be added as a feature of the high-level web framework (vibe.web.web).

  1. point: It seams, that no checking of the existence of path on the file system is done (as string) is done.

You mean for the directory passed to serveStaticFiles, right? That's true and I think that would be a good idea. I'll add that.