Example #1
0
 public RestServer(RestServerConfiguration config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     this.config        = config;
     this.fileResponder = new FileResponder(config.WebRoot, responseWriter);
     listenerThread     = new Thread(HandleRequest);
 }
Example #2
0
 public RestServer(RestServerConfiguration config)
 {
     if (config == null)
     {
         throw new ArgumentNullException("config");
     }
     this.config = config;
     this.fileResponder = new FileResponder(config.WebRoot, responseWriter);
     listenerThread = new Thread(HandleRequest);
 }
Example #3
0
        public static void Main(string[] args)
        {
            var config = new RestServerConfiguration
            {
                Host = "+",
                WebRoot = string.Format("..{0}..{0}server{0}files{0}", Path.DirectorySeparatorChar)
            };

            SetLoggingEvents();

            RestServer server = new RestServer(config);
            MyResource resources = new MyResource();
            server.AddResource(resources.FooRoute, resources.WriteMore);
            server.AddResource(resources.NotFoundRoute, resources.WriteNotFound);
            server.AddResource(resources.ExceptionRoute, (c) => { throw new Exception("exception happend");});
            server.AddResource(resources.HtmlWithCssRoute, resources.WriteHtmlWithCss);
            //            server.AddResource(route.MatchEverythingRoute, route.WriteRawUrl);
            server.Start();

            while (server.IsListening)
            {
                Thread.Sleep(300);
            }
        }