public void Register(string AssetDir, RouterCollection Router, string URLPrefix = "/assets", bool IndexDirectories = false) { if (!Directory.Exists(AssetDir)) { throw new ArgumentException($"Directory not found: {AssetDir}"); } var dirinfo = new DirectoryInfo(AssetDir); if (IndexDirectories) { Router.GET($"{URLPrefix}", r => Get(dirinfo.FullName, $"{URLPrefix}", true)); Router.HEAD($"{URLPrefix}", r => Head(dirinfo.FullName, $"{URLPrefix}", true)); } foreach (var subdir in dirinfo.GetDirectories()) { Register(subdir.FullName, Router, $"{URLPrefix}/{subdir.Name}", IndexDirectories); } foreach (var file in dirinfo.GetFiles()) { Router.GET($"{URLPrefix}/{file.Name}", r => Get(file.FullName, $"{URLPrefix}/{file.Name}", false)); Router.HEAD($"{URLPrefix}/{file.Name}", r => Head(file.FullName, $"{URLPrefix}/{file.Name}", false)); } }
public Application(string Name, IPEndPoint Endpoint, IEnumerable <Method> AcceptedMethods, string LogDir, string URLPrefix = "/") { Router = new RouterCollection(URLPrefix); Server = new Server(this, Endpoint, AcceptedMethods, Path.Combine(LogDir, "error.log"), Path.Combine(LogDir, "access.log")); AssetServer = new AssetServer(this); this.URLPrefix = URLPrefix; }