aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rw-r--r--api/src/db.rs5
-rw-r--r--api/src/main.rs2
2 files changed, 4 insertions, 3 deletions
diff --git a/api/src/db.rs b/api/src/db.rs
index 59b86c5..932a5f0 100644
--- a/api/src/db.rs
+++ b/api/src/db.rs
@@ -1,3 +1,4 @@
+use dotenv::dotenv;
use mongodb::{error::Error, options::ClientOptions, Client};
use std::env;
@@ -10,6 +11,7 @@ pub struct User {
}
pub async fn init() -> Result<Client, Error> {
+ dotenv().ok();
let host = env::var("MONGO_HOST").expect("MONGO_HOST is not set");
let port = env::var("MONGO_PORT").expect("MONGO_PORT is not set");
@@ -17,6 +19,5 @@ pub async fn init() -> Result<Client, Error> {
client_options.app_name = Some("pressure-api".to_string());
- let client = Client::with_options(client_options)?;
- Ok(client)
+ return Client::with_options(client_options);
}
diff --git a/api/src/main.rs b/api/src/main.rs
index 8d4f537..ad55992 100644
--- a/api/src/main.rs
+++ b/api/src/main.rs
@@ -18,7 +18,7 @@ fn init_log() {
#[actix_rt::main]
async fn main() -> Result<()> {
init_log();
- let client = web::Data::new(Mutex::new(db::init()));
+ let client = web::Data::new(Mutex::new(db::init().await.unwrap()));
HttpServer::new(move || {
App::new()
.app_data(client.clone())