mirror of
https://github.com/redstrate/Kawari.git
synced 2025-05-12 22:57:45 +00:00
I plan on including some Bootstrap styling, and I don't want that to bloat the binaries. This also means people can easily modify the pages if they want.
74 lines
2 KiB
Rust
74 lines
2 KiB
Rust
use axum::response::Html;
|
|
use axum::{Router, routing::get};
|
|
use kawari::config::get_config;
|
|
use minijinja::Environment;
|
|
use minijinja::context;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
fn setup_default_environment() -> Environment<'static> {
|
|
let mut env = Environment::new();
|
|
env.add_template_owned(
|
|
"web.html",
|
|
std::fs::read_to_string("resources/templates/web.html").expect("Failed to find template!"),
|
|
)
|
|
.unwrap();
|
|
env.add_template_owned(
|
|
"worldstatus.html",
|
|
std::fs::read_to_string("resources/templates/worldstatus.html")
|
|
.expect("Failed to find template!"),
|
|
)
|
|
.unwrap();
|
|
env.add_template_owned(
|
|
"account.html",
|
|
std::fs::read_to_string("resources/templates/account.html")
|
|
.expect("Failed to find template!"),
|
|
)
|
|
.unwrap();
|
|
|
|
env
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
struct GateStatus {
|
|
status: i32,
|
|
}
|
|
|
|
async fn root() -> Html<String> {
|
|
let config = get_config();
|
|
|
|
let environment = setup_default_environment();
|
|
let template = environment.get_template("web.html").unwrap();
|
|
Html(
|
|
template
|
|
.render(context! { login_server => config.login.server_name })
|
|
.unwrap(),
|
|
)
|
|
}
|
|
|
|
async fn world_status() -> Html<String> {
|
|
let config = get_config();
|
|
|
|
let environment = setup_default_environment();
|
|
let template = environment.get_template("worldstatus.html").unwrap();
|
|
Html(
|
|
template
|
|
.render(context! { login_open => config.frontier.login_open, worlds_open => config.frontier.worlds_open })
|
|
.unwrap(),
|
|
)
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let app = Router::new()
|
|
.route("/", get(root))
|
|
.route("/worldstatus", get(world_status));
|
|
|
|
let config = get_config();
|
|
|
|
let addr = config.web.get_socketaddr();
|
|
tracing::info!("Server started on {addr}");
|
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
|
axum::serve(listener, app).await.unwrap();
|
|
}
|