vibe.d beta banner
get vibe.d
0.8.2

Asynchronous I/O that doesn’t get in your way, written in D

Function serveStaticFiles

Returns a request handler that serves files from the specified directory.

void delegate(HTTPServerRequest, HTTPServerResponse) serveStaticFiles (
  Path local_path,
  HTTPFileServerSettings settings = null
);

void delegate(HTTPServerRequest, HTTPServerResponse) serveStaticFiles (
  string local_path,
  HTTPFileServerSettings settings = null
);

See Also

serveStaticFile

Example

import vibe.http.fileserver;
import vibe.http.router;
import vibe.http.server;

void setupServer()
{
	auto router = new URLRouter;
	// add other routes here
	router.get("*", serveStaticFiles("public/"));

	auto settings = new HTTPServerSettings;
	listenHTTP(settings, router);
}

Example

This example serves all files in the "public" sub directory with an added prefix "static/" so that they don't interfere with other registered routes.

import vibe.http.fileserver;
import vibe.http.router;
import vibe.http.server;

void setupRoutes()
{
 	auto router = new URLRouter;
	// add other routes here

	auto fsettings = new HTTPFileServerSettings;
 		fsettings.serverPathPrefix = "/static";
 		router.get("static/*", serveStaticFiles("public/", fsettings));

	auto settings = new HTTPServerSettings;
	listenHTTP(settings, router);
 	}
Authors

Sönke Ludwig

Copyright

© 2012 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.