Browse Source

Make port configurable

Thomas Dy 8 years ago
parent
commit
ee6581f9c1
3 changed files with 6 additions and 1 deletions
  1. 1 0
      config.json.example
  2. 1 0
      rust-server/src/config.rs
  3. 4 1
      rust-server/src/main.rs

+ 1 - 0
config.json.example

@@ -1,4 +1,5 @@
 {
+    "port": 8000,
     "email": "<user email>",
     "token": "<user token>",
     "whitelist": [

+ 1 - 0
rust-server/src/config.rs

@@ -5,6 +5,7 @@ use std::io::prelude::*;
 
 #[derive(RustcDecodable, Debug)]
 pub struct Config {
+    pub port: Option<u16>,
     pub email: String,
     pub token: String,
     pub whitelist: Vec<String>

+ 4 - 1
rust-server/src/main.rs

@@ -10,8 +10,11 @@ use hyper::Server;
 fn main() {
     let config_path = env::args().nth(1).unwrap_or("./config.json".to_string());
     let cfg = config::load(&config_path);
+    let port = cfg.port.unwrap_or(8000);
     let site = handler::new(cfg);
 
-    Server::http("127.0.0.1:8000").unwrap()
+    let listen = format!("127.0.0.1:{}", port);
+    println!("Listening on {}", listen);
+    Server::http(listen.as_ref() as &str).unwrap()
         .handle(site).unwrap();
 }