Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var webBuilder = Statik.GetWebBuilder();

            webBuilder.RegisterMvcServices();
            webBuilder.RegisterMvc("/hello", new
            {
                controller = "Example",
                action     = "Index",
                other      = 1 /* You can pass other values to the action, traditional MVC */
            });

            using (var host = webBuilder.BuildWebHost())
            {
                host.Listen();
                Console.WriteLine($"Listening on port {StatikDefaults.DefaultPort}...");
                Console.WriteLine($"Try visiting http://localhost:{StatikDefaults.DefaultPort}/hello");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();

                // NOTE: You can export this host to a directory.
                // Useful for GitHub pages, etc.
                // await Statik.ExportHost(host, "./somewhere");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var webBuilder = Statik.GetWebBuilder();

            webBuilder.RegisterMvcServices();

            var pagesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "pages");

            var rootTreeItem = Statik.GetPageDirectoryLoader().LoadFiles(new PhysicalFileProvider(pagesDirectory),
                                                                         "*.md",
                                                                         "index.md");

            void RegisterTreeItem(PageTreeItem <IFileInfo> treeItem)
            {
                if (!treeItem.Data.IsDirectory)
                {
                    webBuilder.RegisterMvc(treeItem.Path,
                                           new
                    {
                        controller = "Pages",
                        action     = "Index",
                        treeItem
                    });
                }

                foreach (var child in treeItem.Children)
                {
                    RegisterTreeItem(child);
                }
            }

            RegisterTreeItem(rootTreeItem);

            using (var host = webBuilder.BuildWebHost())
            {
                host.Listen();
                Console.WriteLine($"Listening on port {StatikDefaults.DefaultPort}...");
                Console.WriteLine($"Try visiting http://localhost:{StatikDefaults.DefaultPort}/hello");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var webBuilder = Statik.GetWebBuilder();

            webBuilder.Register("/hello", async context =>
            {
                await context.Response.WriteAsync($"The time is {DateTime.Now.ToLongTimeString()}");
            });

            using (var host = webBuilder.BuildWebHost())
            {
                host.Listen();
                Console.WriteLine($"Listening on port {StatikDefaults.DefaultPort}...");
                Console.WriteLine($"Try visiting http://localhost:{StatikDefaults.DefaultPort}/hello");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();

                // NOTE: You can export this host to a directory.
                // Useful for GitHub pages, etc.
                // await Statik.ExportHost(host, "./somewhere");
            }
        }