~skye/pulver/src/main.rs
view raw
use axum::{
routing::{get, post},
Router,
};
use pulver::{act, CFG};
use sbcom::macros::*;
use sbse::fatal;
use std::fs;
#[tokio::main]
async fn main() {
let css = match fs::read_to_string(format!("{}/style.css", &CFG.css)) {
Ok(x) => x,
Err(e) => fatal!("failed to read css stylesheet \"{}\": {e}", CFG.css),
};
let app = Router::new()
.route("/", get(act::index))
.route(
"/style.css",
get(([("Content-Type", "text/css")], css.clone())),
)
.route("/act/mkthread", post(act::mkthread))
.route("/act/mkpost", post(act::mkpost))
.route("/data/:p", get(act::data))
.route("/:b/:i", get(act::thread))
.route("/:b/", get(act::board));
let addr = format!("{}:{}", CFG.addr, CFG.port);
axum::serve(
match tokio::net::TcpListener::bind(&addr).await {
Ok(x) => {
log!("bound to {addr}");
x
}
Err(e) => fatal!("failed to bind to address {addr}: {e}"),
},
app,
)
.await
.unwrap();
}