2020-08-25 21:19:53 +00:00
|
|
|
use sqlx::postgres::PgPool;
|
|
|
|
use std::net::TcpListener;
|
2020-12-05 16:59:56 +00:00
|
|
|
use zero2prod::configuration::get_configuration;
|
|
|
|
use zero2prod::startup::run;
|
2020-08-25 21:19:53 +00:00
|
|
|
|
2021-02-11 08:11:45 +00:00
|
|
|
#[actix_web::main]
|
2020-10-18 13:13:27 +00:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2020-08-25 21:19:53 +00:00
|
|
|
let configuration = get_configuration().expect("Failed to read configuration.");
|
|
|
|
let connection_pool = PgPool::connect(&configuration.database.connection_string())
|
|
|
|
.await
|
2020-10-18 13:13:27 +00:00
|
|
|
.expect("Failed to connect to Postgres.");
|
2020-09-01 14:54:53 +00:00
|
|
|
|
|
|
|
// 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.
|
2020-08-31 01:05:21 +00:00
|
|
|
let address = format!("127.0.0.1:{}", configuration.application_port);
|
|
|
|
let listener = TcpListener::bind(address)?;
|
|
|
|
run(listener, connection_pool)?.await?;
|
2020-08-25 21:19:53 +00:00
|
|
|
Ok(())
|
2020-08-23 10:34:29 +00:00
|
|
|
}
|