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

88 lines
2 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};
use kawari::config::{Config, get_config};
2023-10-04 19:06:59 -04:00
#[derive(Debug, Clone, Serialize, Deserialize)]
struct GateStatus {
status: i32,
}
2024-06-29 14:06:44 -04:00
async fn get_login_status() -> Json<GateStatus> {
tracing::info!("Requesting login status...");
2024-06-29 14:06:44 -04:00
let config = get_config();
2024-06-29 14:06:44 -04:00
Json(GateStatus {
status: config.login_open.into()
2024-06-29 14:06:44 -04:00
})
}
async fn get_world_status() -> Json<GateStatus> {
tracing::info!("Requesting world status...");
2023-10-05 12:09:05 -04:00
let config = get_config();
2023-10-04 19:06:59 -04:00
Json(GateStatus {
status: config.login_open.into()
2023-10-04 19:06:59 -04:00
})
}
2024-05-11 13:07:00 -04:00
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Banner {
link: String,
lsb_banner: String
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct NewsItem {
date: String,
id: String,
tag: String,
title: String,
url: String
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Headline {
banner: Vec<Banner>,
news: Vec<NewsItem>,
pinned: Vec<NewsItem>,
topics: Vec<NewsItem>,
}
async fn get_headline() -> Json<Headline> {
tracing::info!("Requesting headline...");
Json(Headline {
banner: vec![],
news: vec![NewsItem {
date: "".to_string(),
id: "".to_string(),
tag: "".to_string(),
title: "Test News Item".to_string(),
url: "".to_string(),
}],
pinned: vec![],
topics: vec![],
})
}
2023-10-04 19:06:59 -04:00
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new()
2024-06-29 14:06:44 -04:00
.route("/worldStatus/gate_status.json", get(get_world_status))
.route("/worldStatus/login_status.json", get(get_login_status))
2024-05-11 13:07:00 -04:00
.route("/news/headline.json", get(get_headline));
2023-10-04 19:06:59 -04:00
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();
}