use tide::http::mime;
use tide::utils::After;
use tide::{Request, Response, log};
use tide_jsx::{view, rsx, component};
use tide_jsx::html::HTML5Doctype;
#[component]
fn Heading<'title>(title: &'title str) {
rsx! {
{title}
}
}
async fn index(_req: Request<()>) -> tide::Result {
view! {
<>
{"Tide JSX"}
>
}
}
#[async_std::main]
async fn main() -> tide::Result<()> {
log::start();
let mut app = tide::new();
app.with(tide::log::LogMiddleware::new());
app.with(After(|mut res: Response| async {
if let Some(err) = res.error() {
let msg = format!("Error: {:?}
", err);
res.set_status(err.status());
res.set_content_type(mime::HTML);
res.set_body(msg);
}
Ok(res)
}));
app.at("/").get(index);
app.listen("127.0.0.1:5000").await?;
Ok(())
}