55 lines
2 KiB
Rust
55 lines
2 KiB
Rust
use maud::{DOCTYPE, html};
|
|
use rouille::router;
|
|
|
|
mod db;
|
|
mod project;
|
|
|
|
fn main() {
|
|
println!("Starting server on localhost:8080");
|
|
|
|
rouille::start_server("localhost:8080", move |request| {
|
|
router!(request,
|
|
(GET) ["/"] => {
|
|
rouille::Response::redirect_302("/projects")
|
|
},
|
|
(GET) ["/main.css"] => {
|
|
let css = include_bytes!("main.css");
|
|
rouille::Response::from_data("text/css", css.as_ref())
|
|
},
|
|
(GET) ["/project-card.js"] => {
|
|
let js = include_bytes!("project-card.js");
|
|
rouille::Response::from_data("application/javascript", js.as_ref())
|
|
},
|
|
(GET) ["/projects"] => {
|
|
let projects = db::list_all_projects().unwrap_or_default();
|
|
|
|
let markup = html! {
|
|
(DOCTYPE)
|
|
html {
|
|
head {
|
|
meta charset="utf-8";
|
|
meta name="viewport" content="width=device-width, initial-scale=1";
|
|
link rel="stylesheet" href="/main.css";
|
|
script src="/project-card.js" {}
|
|
}
|
|
body {
|
|
main {
|
|
section {
|
|
@for project in &projects {
|
|
project-card
|
|
title=(project.title)
|
|
percentage=(project.percentage_completed)
|
|
archived=(project.archived) {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
rouille::Response::html(markup.into_string())
|
|
},
|
|
_ => rouille::Response::empty_404()
|
|
)
|
|
});
|
|
}
|