2025-03-17 17:31:22 -04:00
|
|
|
use axum::response::Html;
|
|
|
|
use axum::{Router, routing::get};
|
2025-03-08 21:54:03 -05:00
|
|
|
use kawari::config::get_config;
|
2025-03-31 22:03:33 -04:00
|
|
|
use minijinja::Environment;
|
2025-03-08 21:54:03 -05:00
|
|
|
use minijinja::context;
|
2025-03-08 13:27:41 -05:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-05-03 11:56:27 -04:00
|
|
|
use tower_http::services::ServeDir;
|
2024-05-11 14:02:55 -04:00
|
|
|
|
2025-03-31 22:03:33 -04:00
|
|
|
fn setup_default_environment() -> Environment<'static> {
|
|
|
|
let mut env = Environment::new();
|
2025-05-03 11:56:27 -04:00
|
|
|
env.add_template_owned(
|
|
|
|
"layout.html",
|
|
|
|
std::fs::read_to_string("resources/templates/layout.html")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2025-05-03 11:12:56 -04:00
|
|
|
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(
|
2025-03-31 22:03:33 -04:00
|
|
|
"worldstatus.html",
|
2025-05-03 11:12:56 -04:00
|
|
|
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!"),
|
2025-03-31 22:03:33 -04:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
env
|
|
|
|
}
|
|
|
|
|
2024-05-11 14:02:55 -04:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct GateStatus {
|
|
|
|
status: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn root() -> Html<String> {
|
2025-04-05 22:40:44 -04:00
|
|
|
let config = get_config();
|
2024-05-11 14:10:49 -04:00
|
|
|
|
|
|
|
let environment = setup_default_environment();
|
2025-04-05 22:40:44 -04:00
|
|
|
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
|
2025-03-22 16:47:21 -04:00
|
|
|
.render(context! { login_open => config.frontier.login_open, worlds_open => config.frontier.worlds_open })
|
2025-03-08 13:27:41 -05:00
|
|
|
.unwrap(),
|
|
|
|
)
|
2024-05-11 14:10:49 -04:00
|
|
|
}
|
|
|
|
|
2024-05-11 14:02:55 -04:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let app = Router::new()
|
|
|
|
.route("/", get(root))
|
2025-05-03 11:56:27 -04:00
|
|
|
.route("/worldstatus", get(world_status))
|
|
|
|
.nest_service("/static", ServeDir::new("resources/static"));
|
2024-05-11 14:02:55 -04:00
|
|
|
|
2025-03-22 16:47:21 -04:00
|
|
|
let config = get_config();
|
|
|
|
|
|
|
|
let addr = config.web.get_socketaddr();
|
2025-03-29 20:05:20 -04:00
|
|
|
tracing::info!("Server started on {addr}");
|
2025-03-22 21:44:28 -04:00
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
|
|
|
axum::serve(listener, app).await.unwrap();
|
2025-03-08 13:27:41 -05:00
|
|
|
}
|