1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-05-12 22:57:45 +00:00
kawari/src/bin/kawari-web.rs

75 lines
2 KiB
Rust
Raw Normal View History

use axum::response::Html;
use axum::{Router, routing::get};
use kawari::config::get_config;
use minijinja::Environment;
use minijinja::context;
2025-03-08 13:27:41 -05:00
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(),
)
2024-06-29 14:14:07 -04:00
}
async fn world_status() -> Html<String> {
let config = get_config();
let environment = setup_default_environment();
let template = environment.get_template("worldstatus.html").unwrap();
2025-03-08 13:27:41 -05:00
Html(
template
.render(context! { login_open => config.frontier.login_open, worlds_open => config.frontier.worlds_open })
2025-03-08 13:27:41 -05:00
.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();
2025-03-29 20:05:20 -04:00
tracing::info!("Server started on {addr}");
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
axum::serve(listener, app).await.unwrap();
2025-03-08 13:27:41 -05:00
}