about summary refs log tree commit diff
path: root/server/src
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-01-12 18:04:30 +0100
committerMelonai <einebeere@gmail.com>2021-01-12 18:04:30 +0100
commit6e8a1117ddef390453d6b695c301d7f4d219f947 (patch)
treec960d95454ce332bdbaaca95c21593e67948c3f5 /server/src
parentfa1189658a911db852ba974a7382509fb4ffbb7c (diff)
downloadshorest-6e8a1117ddef390453d6b695c301d7f4d219f947.tar.zst
shorest-6e8a1117ddef390453d6b695c301d7f4d219f947.zip
Full cacheable Docker deployment with database
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 6ca2fe3..92df222 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -11,12 +11,12 @@ use types::*;
 use actix_web::{middleware, web, HttpServer, App, HttpResponse, Result, HttpRequest};
 use actix_web::web::{Json, Path, Data};
 use diesel::{PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, QueryResult};
-use dotenv::dotenv;
 use diesel::r2d2::{ConnectionManager, Pool};
 use actix_files::{Files, NamedFile};
 
 fn establish_connection() -> Pool<ConnectionManager<PgConnection>> {
-    let database_url = std::env::var("DATABASE_URL").expect("Cannot find DATABASE_URL. Check .env file.");
+    let password = std::env::var("POSTGRES_PASSWORD").expect("Cannot find POSTGRES_PASSWORD in environment.");
+    let database_url = format!("postgresql://postgres:{}@postgres/shorest", password);
     let manager = ConnectionManager::<PgConnection>::new(database_url);
     Pool::builder().max_size(4).build(manager).expect("Failed to create pool.")
 }
@@ -70,7 +70,7 @@ fn add_to_database_safely(mut hash: String, user_url: String, connection: &PgCon
 }
 
 async fn root(req: HttpRequest) -> HttpResponse {
-    NamedFile::open("./client/build/index.html").unwrap().into_response(&req).unwrap()
+    NamedFile::open("./client/index.html").unwrap().into_response(&req).unwrap()
 }
 
 async fn shorten(params: Json<UserData>, state: Data<PoolState>) -> HttpResponse {
@@ -94,7 +94,6 @@ async fn redirect(info: Path<String>, state: Data<PoolState>) -> HttpResponse {
 
 #[actix_rt::main]
 async fn main() -> std::io::Result<()> {
-    dotenv().ok();
     std::env::set_var("RUST_LOG", "actix_web=info");
     env_logger::init();
 
@@ -118,7 +117,7 @@ async fn main() -> std::io::Result<()> {
                     .route(web::get().to(redirect))
             )
             .service(
-                Files::new("/client/", "./client/build/")
+                Files::new("/client/", "./client/")
             )
     })
         .bind(("0.0.0.0", port))?