CryptoFox-Mukan-Edition/src/api/routes.rs

31 lines
1.1 KiB
Rust

use axum::{
middleware,
routing::{delete, get, post},
Router,
};
use crate::api::{auth::require_auth, bots, events, mode, positions};
use crate::AppState;
pub fn build(state: AppState) -> Router {
let api = Router::new()
.route("/symbols", get(bots::list_symbols))
.route("/bots", get(bots::list_bots).post(bots::create_bot))
.route("/bots/:id", delete(bots::delete_bot))
.route("/bots/:id/start", post(bots::start_bot))
.route("/bots/:id/stop", post(bots::stop_bot))
.route("/positions", get(positions::open_positions))
.route("/positions/closed", get(positions::closed_positions))
.route("/mode", get(mode::get_mode).post(mode::set_mode))
.route("/events", get(events::sse_handler))
.layer(middleware::from_fn_with_state(state.clone(), require_auth));
Router::new()
.nest("/api", api)
.route("/", get(index_handler))
.with_state(state)
}
async fn index_handler() -> axum::response::Html<&'static str> {
axum::response::Html(include_str!("../web/index.html"))
}