aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-08-19 12:10:58 +0200
committerlonkaars <loek@pipeframe.xyz>2021-08-19 12:10:58 +0200
commit160c0208b840e9c93069ebc0e590110984c049e0 (patch)
treeb1f287b7643ccbc5ed80ad0dba61fdd32b61bb36 /api/src
parent246851e85c3ac1d62853ee7622ad86549aaf40e2 (diff)
api loading db w/ db access in endpoint handlersHEADmaster
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())