mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-05-18 16:28:08 +00:00
28 lines
1.2 KiB
Rust
28 lines
1.2 KiB
Rust
use chapter04::configuration::get_configuration;
|
|
use chapter04::startup::run;
|
|
use chapter04::telemetry::{get_subscriber, init_subscriber};
|
|
use sqlx::postgres::PgPool;
|
|
use std::net::TcpListener;
|
|
|
|
#[actix_rt::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
let subscriber = get_subscriber("zero2prod".into(), "info".into());
|
|
init_subscriber(subscriber);
|
|
|
|
let configuration = get_configuration().expect("Failed to read configuration.");
|
|
let connection_pool = PgPool::connect(&configuration.database.connection_string())
|
|
.await
|
|
.expect("Failed to connect to Postgres.");
|
|
|
|
// Here we choose to bind explicitly to localhost, 127.0.0.1, for security
|
|
// reasons. This binding may cause issues in some environments. For example,
|
|
// it causes connectivity issues running in WSL2, where you cannot reach the
|
|
// server when it is bound to WSL2's localhost interface. As a workaround,
|
|
// you can choose to bind to all interfaces, 0.0.0.0, instead, but be aware
|
|
// of the security implications when you expose the server on all interfaces.
|
|
let address = format!("127.0.0.1:{}", configuration.application_port);
|
|
let listener = TcpListener::bind(address)?;
|
|
run(listener, connection_pool)?.await?;
|
|
Ok(())
|
|
}
|