static void Main(string[] args) { // Template generators are used to render templates // (convert code + html to pure html). TemplateManager mgr = new TemplateManager(); mgr.Add("haml", new HamlGenerator()); // The httpserver is quite dumb and will only serve http, nothing else. HttpServer server = new HttpServer(); // a controller mode implements a MVC pattern // You'll add all controllers to the same module. ControllerModule mod = new ControllerModule(); mod.Add(new UserController(mgr)); server.Add(mod); // file module will be handling files FileModule fh = new FileModule("/", Environment.CurrentDirectory); fh.AddDefaultMimeTypes(); server.Add(fh); // Let's start pure HTTP, we can also start a HTTPS listener. server.Start(IPAddress.Any, 8081); Console.ReadLine(); }
private static void AddMimeTypes(FileModule fm) { fm.AddDefaultMimeTypes(); fm.MimeTypes["htc"] = "text/x-component"; fm.MimeTypes["json"] = "application/json"; fm.MimeTypes["map"] = "application/json"; fm.MimeTypes["htm"] = "text/html; charset=utf-8"; fm.MimeTypes["html"] = "text/html; charset=utf-8"; fm.MimeTypes["hbs"] = "application/x-handlebars-template"; fm.MimeTypes["woff"] = "application/font-woff"; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleServer"/> class. /// </summary> public SimpleServer() { Add(new BodyDecoders.MultiPartDecoder()); Add(new BodyDecoders.UrlDecoder()); var fileModule = new FileModule(); fileModule.AddDefaultMimeTypes(); AddEmbeddedResources(Assembly.GetCallingAssembly(), fileModule); AddFileResources(Assembly.GetCallingAssembly(), fileModule); }
public static void init() { HttpServer server = new HttpServer(); FileModule module = new FileModule("/", main.config.path_module); module.AddDefaultMimeTypes(); server.Add(module); server.Add(new webProcess()); server.Start(IPAddress.Parse(main.config.site_ip), main.config.site_port); main.show_notification(main.page_Site, 3000); }
/// <summary> /// 简单HTTP服务器 /// </summary> public SimpleServer(string serverName) : base(serverName) { // 增加消息体解析器 Add(new MultiPartDecoder()); Add(new UrlDecoder()); // 增加文件模块 var fileModule = new FileModule(); fileModule.AddDefaultMimeTypes(); AddEmbeddedResources(Assembly.GetCallingAssembly(), fileModule); AddFileResources(Assembly.GetCallingAssembly(), fileModule); }
private static HttpServer.HttpServer CreateServer(IDictionary <string, string> options) { HttpServer.HttpServer server = new HttpServer.HttpServer(); server.Add(new AuthenticationHandler()); server.Add(new ControlHandler()); string webroot = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string install_webroot = System.IO.Path.Combine(Library.AutoUpdater.UpdaterManager.InstalledBaseDir, "webroot"); #if DEBUG // Easy test for extensions while debugging install_webroot = Library.AutoUpdater.UpdaterManager.InstalledBaseDir; if (!System.IO.Directory.Exists(System.IO.Path.Combine(webroot, "webroot"))) { //For debug we go "../../../.." to get out of "GUI/Duplicati.GUI.TrayIcon/bin/debug" string tmpwebroot = System.IO.Path.GetFullPath(System.IO.Path.Combine(webroot, "..", "..", "..", "..")); tmpwebroot = System.IO.Path.Combine(tmpwebroot, "Server"); if (System.IO.Directory.Exists(System.IO.Path.Combine(tmpwebroot, "webroot"))) { webroot = tmpwebroot; } else { //If we are running the server standalone, we only need to exit "bin/Debug" tmpwebroot = System.IO.Path.GetFullPath(System.IO.Path.Combine(webroot, "..", "..")); if (System.IO.Directory.Exists(System.IO.Path.Combine(tmpwebroot, "webroot"))) { webroot = tmpwebroot; } } } #endif webroot = System.IO.Path.Combine(webroot, "webroot"); if (options.ContainsKey(OPTION_WEBROOT)) { string userroot = options[OPTION_WEBROOT]; #if DEBUG //In debug mode we do not care where the path points #else //In release mode we check that the user supplied path is located // in the same folders as the running application, to avoid users // that inadvertently expose top level folders if (!string.IsNullOrWhiteSpace(userroot) && ( userroot.StartsWith(Library.Utility.Utility.AppendDirSeparator(System.Reflection.Assembly.GetExecutingAssembly().Location), Library.Utility.Utility.ClientFilenameStringComparision) || userroot.StartsWith(Library.Utility.Utility.AppendDirSeparator(Program.StartupPath), Library.Utility.Utility.ClientFilenameStringComparision) ) ) #endif { webroot = userroot; install_webroot = webroot; } } if (install_webroot != webroot && System.IO.Directory.Exists(System.IO.Path.Combine(install_webroot, "customized"))) { var customized_files = new FileModule("/customized/", System.IO.Path.Combine(install_webroot, "customized")); customized_files.AddDefaultMimeTypes(); customized_files.MimeTypes.Add("htc", "text/x-component"); customized_files.MimeTypes.Add("json", "application/json"); customized_files.MimeTypes.Add("map", "application/json"); customized_files.MimeTypes["htm"] = "text/html; charset=utf-8"; customized_files.MimeTypes["html"] = "text/html; charset=utf-8"; server.Add(customized_files); } var fh = new FileModule("/", webroot); fh.AddDefaultMimeTypes(); fh.MimeTypes.Add("htc", "text/x-component"); fh.MimeTypes.Add("json", "application/json"); fh.MimeTypes.Add("map", "application/json"); fh.MimeTypes["htm"] = "text/html; charset=utf-8"; fh.MimeTypes["html"] = "text/html; charset=utf-8"; server.Add(fh); server.Add(new IndexHtmlHandler(webroot)); #if DEBUG //For debugging, it is nice to know when we get a 404 server.Add(new DebugReportHandler()); #endif return(server); }