mirror of
https://github.com/kristoferssolo/zero2prod.git
synced 2025-10-21 20:10:40 +00:00
20 lines
692 B
Rust
20 lines
692 B
Rust
use std::net::SocketAddr;
|
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
use tokio::net::TcpListener;
|
|
use zero2prod::{configuation::get_configuration, routes::route};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
let configuation = get_configuration().expect("Failed to read configuation.");
|
|
let pool = PgPoolOptions::new()
|
|
.connect(&configuation.database.to_string())
|
|
.await
|
|
.expect("Failed to connect to Postgres.");
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], configuation.application_port));
|
|
let listener = TcpListener::bind(addr)
|
|
.await
|
|
.expect("Failed to bind random port");
|
|
axum::serve(listener, route(pool)).await
|
|
}
|