aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/lib.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-09-30 17:28:24 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-09-30 17:28:24 +0200
commit8f6b34db10c591507271845150314be7a07cee19 (patch)
tree3eacb3ee6d8f00387e2eab7555d1737a3d65c1f1 /planetwars-server/src/lib.rs
parent81781489963dca8488607ef9c0e61fdde2cfd25b (diff)
downloadplanetwars.dev-8f6b34db10c591507271845150314be7a07cee19.tar.xz
planetwars.dev-8f6b34db10c591507271845150314be7a07cee19.zip
add integration test stub
Diffstat (limited to 'planetwars-server/src/lib.rs')
-rw-r--r--planetwars-server/src/lib.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index 6018eee..1301adb 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -112,7 +112,8 @@ fn init_directories(config: &GlobalConfig) -> std::io::Result<()> {
Ok(())
}
-pub fn api() -> Router {
+// just the routes, without connecting state
+fn api() -> Router {
Router::new()
.route("/register", post(routes::users::register))
.route("/login", post(routes::users::login))
@@ -140,6 +141,14 @@ pub fn api() -> Router {
.route("/save_bot", post(routes::bots::save_bot))
}
+// full service
+pub fn create_pw_api(global_config: Arc<GlobalConfig>, db_pool: DbPool) -> Router {
+ Router::new()
+ .nest("/api", api())
+ .layer(Extension(db_pool))
+ .layer(Extension(global_config))
+}
+
pub fn get_config() -> Result<GlobalConfig, ConfigError> {
config::Config::builder()
.add_source(config::File::with_name("configuration.toml"))
@@ -175,16 +184,14 @@ pub async fn run_app() {
tokio::spawn(run_registry(global_config.clone(), db_pool.clone()));
tokio::spawn(run_client_api(global_config.clone(), db_pool.clone()));
- let api_service = Router::new()
- .nest("/api", api())
- .layer(Extension(db_pool))
- .layer(Extension(global_config))
- .into_make_service();
-
// TODO: put in config
let addr = SocketAddr::from(([127, 0, 0, 1], 9000));
- axum::Server::bind(&addr).serve(api_service).await.unwrap();
+ let pw_api_service = create_pw_api(global_config, db_pool).into_make_service();
+ axum::Server::bind(&addr)
+ .serve(pw_api_service)
+ .await
+ .unwrap();
}
// we can also write a custom extractor that grabs a connection from the pool