/// <summary>
/// Initialise a HTTP server
/// </summary>
/// <param name="path">The path to the web root of the http server</param>
public WebServer(string path)
{
_httpServer = new HttpServer.Server();
// Add the controller module and all controllers
var controllerModule = new RestControllerModule();
var cType = typeof(RestRequestController);
AppDomain.CurrentDomain.GetAssemblies().ToList()
.SelectMany(s => s.GetTypes())
.Where(p => p.IsSubclassOf(cType) && p != cType && !p.IsAbstract)
.ToList()
.ForEach(t => controllerModule.Add((RestRequestController)Activator.CreateInstance(t)));
_httpServer.Add(controllerModule);
// Add the basic file module
int cacheDuration = 2592000;
Program.Config.TryGetInt("cacheDuration", out cacheDuration);
var fileModule = new CachedFileModule(Math.Max(0, cacheDuration));
fileModule.Resources.Add(new HttpServer.Resources.FileResources("/", path));
_httpServer.Add(fileModule);
// Set name
string serverName;
Program.Config.TryGetString("name", out serverName, "Touchee");
_httpServer.ServerName = serverName;
// Go to root
_httpServer.Add(new SimpleRouter("/", "/index.html"));
}