diff options
author | Cara Salter <cara@devcara.com> | 2022-06-10 14:40:56 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-06-10 14:40:56 -0400 |
commit | 4c044c28559f356883e4ab3cec437bbb20ce7f89 (patch) | |
tree | e8f697b87a56726689088c2127aba297276e3ffe /src/main.rs | |
parent | f64edeb631bfdefcd757483d7dfbe204daabf1ab (diff) | |
download | solard-4c044c28559f356883e4ab3cec437bbb20ce7f89.tar.gz solard-4c044c28559f356883e4ab3cec437bbb20ce7f89.zip |
planets: Create new planets
Star systems in the palm of your keyboard!
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index c235d41..4dc78a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,12 @@ use axum::{ response::IntoResponse, routing::{get, post}, handler::Handler, - Json, Router + Json, Router, Extension }; use serde::{Deserialize, Serialize}; use solarlib::star::Star; -use std::{net::SocketAddr, time::Duration, str::FromStr}; +use std::{net::SocketAddr, time::Duration, str::FromStr, sync::Arc}; use tower::{BoxError, ServiceBuilder}; use tower_http::trace::TraceLayer; @@ -20,6 +20,10 @@ mod errors; mod handlers; +pub struct State { + pub hw_url: String, +} + #[tokio::main] async fn main() { kankyo::init(); @@ -32,9 +36,14 @@ async fn main() { .with(tracing_subscriber::fmt::layer()) .init(); + let shared_state = Arc::new(State { + hw_url: std::env::var("HOMEWORLD_URL").expect("No Homeworld URL set"), + }); + let app = Router::new() .route("/health", get(health_check)) .route("/planets/list", get(handlers::planets::list)) + .route("/planets/new", post(handlers::planets::new_planet)) .route("/planets/:uuid", get(handlers::planets::get)) .route("/planets/:uuid/shutdown", post(handlers::planets::shutdown)) .route("/planets/:uuid/shutdown/hard", post(handlers::planets::force_shutdown)) @@ -42,6 +51,7 @@ async fn main() { .route("/planets/:uuid/pause", post(handlers::planets::pause)) .route("/planets/:uuid/reboot", post(handlers::planets::reboot)) .route("/planets/:uuid/reboot/hard", post(handlers::planets::force_reboot)) + .route("/planets/:uuid/destroy", post(handlers::planets::no_planet)) .layer( ServiceBuilder::new() .layer(HandleErrorLayer::new(|error: BoxError| async move { if error.is::<tower::timeout::error::Elapsed>() { @@ -57,6 +67,7 @@ async fn main() { .layer(TraceLayer::new_for_http()) .into_inner(), ) + .layer(Extension(shared_state)) .fallback(handler_404.into_service()); let addr = SocketAddr::from_str(std::env::var("BIND_ADDR").unwrap().as_str().into()).unwrap(); |