1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-28 17:37:45 +00:00
kawari/src/bin/kawari-frontier.rs

47 lines
1 KiB
Rust
Raw Normal View History

2023-10-04 19:06:59 -04:00
use std::net::SocketAddr;
use axum::{
Json,
Router, routing::get,
};
use serde::{Deserialize, Serialize};
2023-10-05 12:09:05 -04:00
use kawari::config::Config;
2023-10-04 19:06:59 -04:00
#[derive(Debug, Clone, Serialize, Deserialize)]
struct GateStatus {
status: i32,
}
async fn get_gate_status() -> Json<GateStatus> {
tracing::info!("Requesting gate status...");
2023-10-05 12:09:05 -04:00
let mut is_open = 0;
// read config
if let Ok(data) = std::fs::read_to_string("config.json") {
let config: Config = serde_json::from_str(&data).expect("Failed to parse");
if config.gate_open {
is_open = 1;
}
}
2023-10-04 19:06:59 -04:00
Json(GateStatus {
2023-10-05 12:09:05 -04:00
status: is_open
2023-10-04 19:06:59 -04:00
})
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new()
.route("/worldStatus/gate_status.json", get(get_gate_status));
2023-10-04 19:24:18 -04:00
let addr = SocketAddr::from(([127, 0, 0, 1], 5857));
2023-10-04 19:06:59 -04:00
tracing::info!("Frontier server started on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}