projects/src/main.rs

56 lines
2 KiB
Rust
Raw Normal View History

2026-01-25 14:46:29 -08:00
use maud::{DOCTYPE, html};
2026-01-25 14:37:39 -08:00
use rouille::router;
2026-01-25 14:32:40 -08:00
mod db;
2026-01-25 14:37:39 -08:00
mod project;
2026-01-25 14:31:30 -08:00
2026-01-25 14:28:17 -08:00
fn main() {
println!("Starting server on localhost:8080");
2026-01-25 14:37:39 -08:00
rouille::start_server("localhost:8080", move |request| {
router!(request,
2026-01-25 14:48:33 -08:00
(GET) ["/"] => {
rouille::Response::redirect_302("/projects")
},
2026-01-25 14:37:39 -08:00
(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())
},
2026-01-25 14:46:29 -08:00
(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())
},
2026-01-25 14:37:39 -08:00
_ => rouille::Response::empty_404()
)
2026-01-25 14:28:17 -08:00
});
}