Browse Source

Allow configuring HOST and PORT

master
Dylan Baker 1 year ago
parent
commit
edf0a83254
2 changed files with 9 additions and 6 deletions
  1. 5
    3
      .env.example
  2. 4
    3
      src/main.rs

+ 5
- 3
.env.example View File

@@ -1,5 +1,7 @@
1
-ADMIN_USERNAME=
2
-ADMIN_PASSWORD=
1
+ADMIN_USERNAME=admin
2
+ADMIN_PASSWORD=admin
3 3
 POSTS_DIR=
4 4
 TIDE_SECRET=
5
-LOGIN_PATH=
5
+LOGIN_PATH=/login
6
+HOSTNAME=127.0.0.1
7
+PORT=8080

+ 4
- 3
src/main.rs View File

@@ -1,8 +1,7 @@
1 1
 use dotenv;
2 2
 
3
-use tide::utils::After;
4
-
5 3
 use middleware::*;
4
+use tide::utils::After;
6 5
 
7 6
 mod fs;
8 7
 mod middleware;
@@ -20,6 +19,8 @@ async fn main() -> std::io::Result<()> {
20 19
     tide::log::start();
21 20
 
22 21
     let login_path = std::env::var("LOGIN_PATH").unwrap_or(String::from("/login"));
22
+    let hostname = std::env::var("HOSTNAME").unwrap_or(String::from("127.0.0.1"));
23
+    let port = std::env::var("PORT").unwrap_or(String::from("8080"));
23 24
     let mut app = tide::with_state(State {
24 25
         login_path: login_path.clone(),
25 26
     });
@@ -46,7 +47,7 @@ async fn main() -> std::io::Result<()> {
46 47
         .post(routes::login);
47 48
     app.at("/logout").with(require_auth).post(routes::logout);
48 49
 
49
-    app.listen("127.0.0.1:8080").await?;
50
+    app.listen(format!("{}:{}", hostname, port)).await?;
50 51
 
51 52
     Ok(())
52 53
 }

Loading…
Cancel
Save