~skye/git/src/main.rs
view raw
use axum::{
routing::{get, post},
Router,
};
use badboy_git::{act, macros::*, now, CFG};
use std::fs;
use tokio::net::TcpListener;
#[tokio::main]
async fn main() {
/* log the config so it fails at startup instead of after access */
log!("starting up {}", CFG["title"]);
/* read the style file into string */
let style = match fs::read_to_string("css/style.css") {
Ok(x) => {
log!("successfully loaded stylesheet.");
x
}
Err(e) => fatal!("failed to open style.css: {e}"),
};
let app = Router::new()
.route("/", get(act::index))
.route(
"/style.css",
get(([("Content-Type", "text/css")], style.clone())),
)
.route("/err", get(act::err))
.route("/~:n/", get(act::view_user))
.route("/~:n/:r", get(act::view_repo))
.route("/~:n/:r/admin", get(act::admin))
.route("/~:n/:r/src/*p", get(act::view_src))
.route("/~:n/:r/src", get(act::view_src_index))
.route("/~:n/:r/raw/*p", get(act::view_raw))
.route("/~:n/:r/show/*p", get(act::show_raw))
.route("/register", post(act::register))
.route("/login", post(act::login))
.route("/create", post(act::create))
.route("/settings", post(act::settings))
.route("/pin", post(act::pin));
/* address to bind to */
let a = "0.0.0.0:80";
/* run the server */
log!("booting up...");
let tcp = match TcpListener::bind("0.0.0.0:80").await {
Ok(x) => {
log!("bound successfully to {a}");
x
}
Err(e) => fatal!("failed to bind to {a}: {e}"),
};
log!("serving.");
/* we unwrap here because this
* function will never actually exit */
axum::serve(tcp, app).await.unwrap();
}