summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 04f4c99..01a315a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,19 +2,18 @@ mod db;
mod error;
mod handlers;
mod models;
+#[cfg(test)]
+mod tests;
use axum::{
Router,
routing::{delete, get, post, put},
};
use dotenvy::dotenv;
+use sqlx::PgPool;
-#[tokio::main]
-async fn main() -> anyhow::Result<()> {
- tracing_subscriber::fmt::init();
- dotenv().ok();
- let pool = db::connect().await?;
- let app = Router::new()
+fn router(pool: PgPool) -> Router {
+ Router::new()
.route("/", get(handlers::index))
.route("/all", get(handlers::all))
.route("/add", post(handlers::add))
@@ -24,7 +23,15 @@ async fn main() -> anyhow::Result<()> {
.route("/measurement/{id}", get(handlers::measurement_by_id))
.route("/delete/{id}", delete(handlers::delete))
.route("/update/{id}", put(handlers::update))
- .with_state(pool);
+ .with_state(pool)
+}
+
+#[tokio::main]
+async fn main() -> anyhow::Result<()> {
+ tracing_subscriber::fmt::init();
+ dotenv().ok();
+ let pool = db::connect().await?;
+ let app = router(pool);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
tracing::info!("listening at 0.0.0.0:3000");
axum::serve(listener, app).await?;