Exemple #1
0
        private static int Runserver(RunServerOptions options)
        {
            var router = new Router();

            if (Settings.Default.ServeStatic)
            {
                router.Bind("^/static", new StaticServeRouter(Settings.Default.StaticPath));
                router.Bind("^/media", new StaticServeRouter(Settings.Default.FileStorage));
            }

            router.Bind("^/api", ApiViews.Router);
            router.Bind("", GeneralViews.Router);

            if (options.ForceReindex)
                SearchManager.StartIndexingTask();

            IBackend backend;
            if (options.FastCGI)
                backend = new FastCGIBackend(Settings.Default.Port);
            else
                backend = new HttpListenerBackend($"http://127.0.0.1:{Settings.Default.Port}/");

            var app = new App(backend, router);
            app.RegisterMiddleware(new UnitOfWorkMiddleware());
            app.RegisterMiddleware(new SessionMiddleware());
            app.RegisterMiddleware(new ApiMiddleware("/api"));
            app.Run();
            Console.ReadKey();
            return 0;
        }
Exemple #2
0
        public App(IBackend backend, Router router)
        {
            _backend = backend;
            _rootRouter = router;

            var assembly = Assembly.GetExecutingAssembly();
            Template.RegisterTag<Tags.StaticTag>("static");
            Template.FileSystem = new EmbeddedFileSystem(assembly, "Memorandum.Web.Templates");
            Template.NamingConvention = new CSharpNamingConvention();
            Template.RegisterFilter(typeof (Filters));

            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        }
Exemple #3
0
 public void Bind(string pattern, Router router)
 {
     _routers.Add(pattern, router);
 }