From 6e8a1117ddef390453d6b695c301d7f4d219f947 Mon Sep 17 00:00:00 2001 From: Melonai Date: Tue, 12 Jan 2021 18:04:30 +0100 Subject: Full cacheable Docker deployment with database --- server/src/main.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server') 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> { - 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::::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, state: Data) -> HttpResponse { @@ -94,7 +94,6 @@ async fn redirect(info: Path, state: Data) -> 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))? -- cgit 1.4.1