2020-11-24 22:22:47 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2020-10-31 19:53:03 +00:00
|
|
|
use anyhow::*;
|
2020-11-14 02:56:50 +00:00
|
|
|
use log::LevelFilter;
|
2020-12-01 07:31:08 +00:00
|
|
|
use kochab::Server;
|
2020-10-31 19:53:03 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
2020-12-16 16:38:29 +00:00
|
|
|
/// Serving some static content from the filesystem is easy with Kochab
|
|
|
|
///
|
|
|
|
/// This example serves from the `./public` directory on the base route, and adds a
|
|
|
|
/// special one-page bind to `/about` that always serves `README.md`
|
|
|
|
///
|
|
|
|
/// Note, use this module with a little bit of caution. The directory serving feature is
|
|
|
|
/// currently unfinished, and the API is subject to change dramatically in future updates.
|
|
|
|
/// It should be secure, but you may need to do some refactoring in coming updates.
|
2020-10-31 19:53:03 +00:00
|
|
|
async fn main() -> Result<()> {
|
2020-12-16 16:38:29 +00:00
|
|
|
|
|
|
|
// We set up logging so we can see what's happening. This isn't technically required,
|
|
|
|
// and you can use a simpler solution (like env_logger::init()) during production
|
2020-11-14 02:56:50 +00:00
|
|
|
env_logger::builder()
|
2020-11-25 05:42:09 +00:00
|
|
|
.filter_module("kochab", LevelFilter::Debug)
|
2020-11-14 02:56:50 +00:00
|
|
|
.init();
|
|
|
|
|
2020-12-01 07:31:08 +00:00
|
|
|
Server::new()
|
2020-11-24 22:28:54 +00:00
|
|
|
.add_route("/", PathBuf::from("public")) // Serve directory listings & file contents
|
|
|
|
.add_route("/about", PathBuf::from("README.md")) // Serve a single file
|
2020-12-14 00:53:18 +00:00
|
|
|
.serve_ip("localhost:1965")
|
2020-10-31 19:53:03 +00:00
|
|
|
.await
|
|
|
|
}
|