|
|
@@ -1,6 +1,7 @@
|
|
|
use actix_web::{HttpServer, web, App, middleware};
|
|
|
use actix_cors::Cors;
|
|
|
use http_error::HttpError;
|
|
|
+use sqlx::PgPool;
|
|
|
use std::env;
|
|
|
|
|
|
mod http_error;
|
|
|
@@ -14,6 +15,12 @@ async fn main() -> std::io::Result<()> {
|
|
|
|
|
|
let port: u16 = env_var("PORT");
|
|
|
let app_env: String = env_var("APP_ENV");
|
|
|
+ let database_url: String = env_var("DATABASE_URL");
|
|
|
+
|
|
|
+ //Database
|
|
|
+ let pool = PgPool::connect(&database_url)
|
|
|
+ .await
|
|
|
+ .expect("Failed to start Postgres");
|
|
|
|
|
|
//Server
|
|
|
HttpServer::new(move || {
|
|
|
@@ -41,6 +48,7 @@ async fn main() -> std::io::Result<()> {
|
|
|
HttpError::JsonDeserializationError(err.to_string()).into()
|
|
|
})
|
|
|
)
|
|
|
+ .app_data(web::Data::new(pool.clone()))
|
|
|
.configure(routes::user::config)
|
|
|
})
|
|
|
.bind(("0.0.0.0", port))
|