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