public static AppFunc OwinApp(IDictionary<string, object> startupEnv = null)
        {
            var app =
                new List<Func<AppFunc, AppFunc>>()
                    .Use(H5bp.IeEdgeChromeFrameHeader())
                    .Use(H5bp.RemovePoweredBy())
                    .Use(H5bp.CrossDomainRules())
                    .Use(JsonBodyParser.Middleware())
                    .Use(UrlEncoded.Middleware())
                    .Use(MethodOverride.Middleware());

            var router = new RegexRouter(app);
            var template = new RazorEngine.Templating.TemplateService();

            router.Get("/", next =>
                           async env =>
                           {
                               await env.GetResponseBody()
                                   .WriteStringAsync("hi");
                           });

            template.Compile("Hi @Model.name", typeof(DynamicObject), "/hi");
            router.Get(@"/hi/(?<name>((.)*))$", next =>
                            async env =>
                            {
                                var routeParameters = env.GetSimpleOwinRouteParameters();

                                string html = template.Run("/hi", new { name = routeParameters["name"] }.ToDynamicObject());

                                await env.GetResponseBody()
                                    .WriteStringAsync(html);
                            });

            router.Get("/hello", next =>
                                async env =>
                                {
                                    await env.GetResponseBody()
                                        .WriteStringAsync("Hello");
                                });

            router.All("*", NotFound.Middleware());

            return app.ToOwinApp();
        }
Example #2
0
        public static AppFunc App(ISimpleBlogService service)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            var app = new List<Func<AppFunc, AppFunc>>();

            var router = new RegexRouter(app);

            var renderers = new Renderers(service);
            router.Get(@"^\/()$", renderers.Index);
            router.Get(@"^\/()feed.(?<type>xml|json|js)$", renderers.Feed);
            router.Get(@"^\/()robots.txt$", renderers.Robots);
            router.Get(@"^\/([a-f0-9]{40})\/([a-z0-9_-]+)$", renderers.Article);
            router.Get(@"^\/([a-f0-9]{40})\/(.+\.[a-z]{2,4})$", renderers.StaticFile);
            router.Get(@"^\/()([a-z0-9_-]+)$", renderers.Article);
            router.Get(@"^\/()(.+\.[a-z]{2,4})$", renderers.StaticFile);
            router.Get(@"^\/()category\/([\%\.a-z0-9_-]+)$", renderers.Category);
            router.All(@"*", renderers.NotFound);

            return app.ToOwinApp();
        }