diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-30 16:38:02 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-30 16:38:02 +0100 |
commit | c6ca7cf2d1238c05f75a53934ea2f6c91efc3646 (patch) | |
tree | f41f28a9e232bae745fe88e18407d584f9268a51 | |
parent | 4912a0dbe7b1df1e884b53544943319f8f0c0ebb (diff) | |
download | planetwars.dev-c6ca7cf2d1238c05f75a53934ea2f6c91efc3646.tar.xz planetwars.dev-c6ca7cf2d1238c05f75a53934ea2f6c91efc3646.zip |
nest api routes under /api
-rw-r--r-- | planetwars-server/src/lib.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index 665523f..260d668 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -22,27 +22,27 @@ use axum::{ AddExtensionLayer, Router, }; -async fn index_handler() -> &'static str { - "Hello, world!" -} - type ConnectionPool = bb8::Pool<DieselConnectionManager<PgConnection>>; -pub async fn app() -> Router { +pub async fn api() -> Router { let database_url = "postgresql://planetwars:planetwars@localhost/planetwars"; let manager = DieselConnectionManager::<PgConnection>::new(database_url); let pool = bb8::Pool::builder().build(manager).await.unwrap(); - let app = Router::new() - .route("/", get(index_handler)) - .route("/users/register", post(routes::users::register)) - .route("/users/login", post(routes::users::login)) + let api = Router::new() + .route("/register", post(routes::users::register)) + .route("/login", post(routes::users::login)) .route("/users/me", get(routes::users::current_user)) .route("/bots", post(routes::bots::create_bot)) .route("/bots/:bot_id", get(routes::bots::get_bot)) .route("/bots/:bot_id/upload", post(routes::bots::upload_bot_code)) .layer(AddExtensionLayer::new(pool)); - app + api +} + +pub async fn app() -> Router { + let api = api().await; + Router::new().nest("/api", api) } // we can also write a custom extractor that grabs a connection from the pool |