51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use argh::FromArgs;
|
|
use axum::{Json, Router, routing::get};
|
|
use serde_json::{Value, json};
|
|
use std::net::SocketAddr;
|
|
use tracing::info;
|
|
|
|
mod types;
|
|
|
|
#[derive(FromArgs)]
|
|
/// Official OSAKA server implementation
|
|
struct CLIArgs {
|
|
/// server host (default: 0.0.0.0)
|
|
#[argh(option)]
|
|
host: Option<String>,
|
|
|
|
/// server port (default: 80)
|
|
#[argh(option)]
|
|
port: Option<u32>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let cli_args: CLIArgs = argh::from_env();
|
|
let addr: SocketAddr = format!(
|
|
"{}:{}",
|
|
cli_args.host.unwrap_or("0.0.0.0".to_string()),
|
|
cli_args.port.unwrap_or(80)
|
|
)
|
|
.parse()
|
|
.expect("problem parsing arguments into valid socket address. check your config.");
|
|
|
|
let app = Router::new()
|
|
.route("/", get(root))
|
|
// .route("/search/{query}", get(query::search));
|
|
;
|
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
|
info!(
|
|
"OSAKA {} is listening on {}",
|
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
|
addr
|
|
);
|
|
axum::serve(listener, app).await.unwrap();
|
|
Ok(())
|
|
}
|
|
|
|
async fn root() -> Json<Value> {
|
|
Json(json!({"version": "0.0.1"}))
|
|
}
|