You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.rs 894B

123456789101112131415161718192021222324252627282930313233343536
  1. use std::io::ErrorKind;
  2. use tera::{Context, Tera};
  3. use tide::utils::After;
  4. use tide::{Body, Response, Result, StatusCode};
  5. #[async_std::main]
  6. async fn main() -> Result<()> {
  7. tide::log::start();
  8. let mut app = tide::new();
  9. app.with(After(|mut res: Response| async {
  10. if let Some(err) = res.downcast_error::<async_std::io::Error>() {
  11. if let ErrorKind::NotFound = err.kind() {
  12. res.set_status(StatusCode::NotFound);
  13. }
  14. }
  15. Ok(res)
  16. }));
  17. app.with(After(|mut res: Response| async {
  18. res.set_content_type(tide::http::mime::HTML);
  19. Ok(res)
  20. }));
  21. app.at("/admin").get(|_| async {
  22. let tera = Tera::new("templates/**/*.html")?;
  23. let html = tera.render("admin.html", &Context::new())?;
  24. Ok(Body::from_string(html))
  25. });
  26. app.listen("127.0.0.1:8080").await?;
  27. Ok(())
  28. }