35 lines
951 B
Rust
35 lines
951 B
Rust
pub mod announce;
|
|
pub mod files;
|
|
pub mod health;
|
|
pub mod peers;
|
|
pub mod search;
|
|
pub mod stats;
|
|
pub mod ws;
|
|
|
|
use axum::response::Html;
|
|
use axum::{routing::{get, post}, Router};
|
|
use tower_http::cors::CorsLayer;
|
|
use crate::state::SharedState;
|
|
|
|
const INDEX_HTML: &str = include_str!("../../static/index.html");
|
|
|
|
async fn index() -> Html<&'static str> {
|
|
Html(INDEX_HTML)
|
|
}
|
|
|
|
pub fn router(state: SharedState) -> Router {
|
|
let api = Router::new()
|
|
.route("/health", get(health::health))
|
|
.route("/search", get(search::search))
|
|
.route("/files/{file_id}", get(files::get_file))
|
|
.route("/announce", post(announce::announce))
|
|
.route("/peers/{file_id}", get(peers::peers))
|
|
.route("/stats", get(stats::stats))
|
|
.route("/tracker/ws", get(ws::ws_handler))
|
|
.with_state(state);
|
|
|
|
Router::new()
|
|
.route("/", get(index))
|
|
.nest("/api/v1", api)
|
|
.layer(CorsLayer::permissive())
|
|
} |