summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 9e6bef1..72f1cad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,6 @@ use diesel::r2d2::{ConnectionManager, Pool};
 use actix_files::{Files, NamedFile};
 
 fn establish_connection() -> Pool<ConnectionManager<PgConnection>> {
-    dotenv().ok();
     let database_url = std::env::var("DATABASE_URL").expect("Cannot find DATABASE_URL. Check .env file.");
     let manager = ConnectionManager::<PgConnection>::new(database_url);
     Pool::builder().max_size(4).build(manager).expect("Failed to create pool.")
@@ -94,10 +93,15 @@ 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();
 
     let pool = establish_connection();
+    let port = std::env::var("PORT")
+        .unwrap()
+        .parse()
+        .expect("PORT must be a number.");
 
     HttpServer::new(move || {
         App::new()
@@ -116,7 +120,7 @@ async fn main() -> std::io::Result<()> {
                 Files::new("/static/", "./client/static/")
             )
     })
-        .bind("localhost:3000")?
+        .bind(("0.0.0.0", port))?
         .run()
         .await
 }