works almost. todo: config.toml

This commit is contained in:
Jun Kurihara 2022-06-25 09:31:13 -04:00
commit 744b65b738
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
6 changed files with 74 additions and 23 deletions

3
src/config/mod.rs Normal file
View file

@ -0,0 +1,3 @@
mod parse;
pub use parse::parse_opts;

46
src/config/parse.rs Normal file
View file

@ -0,0 +1,46 @@
use crate::{backend::*, constants::*, globals::*};
use hyper::Uri;
use std::{collections::HashMap, sync::Mutex};
// #[cfg(feature = "tls")]
use std::path::PathBuf;
pub fn parse_opts(globals: &mut Globals, backends: &mut HashMap<String, Backend>) {
// TODO:
globals.listen_sockets = LISTEN_ADDRESSES
.to_vec()
.iter()
.flat_map(|x| {
vec![
format!("{}:{}", x, HTTP_LISTEN_PORT).parse().unwrap(),
format!("{}:{}", x, HTTPS_LISTEN_PORT).parse().unwrap(),
]
})
.collect();
globals.http_port = Some(HTTP_LISTEN_PORT);
globals.https_port = Some(HTTPS_LISTEN_PORT);
// TODO:
let mut map_example: HashMap<String, Uri> = HashMap::new();
map_example.insert(
"/maps".to_string(),
"https://www.bing.com".parse::<Uri>().unwrap(),
);
backends.insert(
"localhost".to_string(),
Backend {
app_name: "Localhost to Google except for maps".to_string(),
hostname: "localhost".to_string(),
reverse_proxy: ReverseProxy {
// default_destination_uri: "http://www.google.com".parse::<Uri>().unwrap(),
default_destination_uri: "http://abehiroshi.la.coocan.jp/".parse::<Uri>().unwrap(), // httpのみの場合の好例
destination_uris: map_example,
},
https_redirection: Some(false), // TODO: ここはtlsが存在する時はSomeにすべき。Noneはtlsがないときのみのはず
tls_cert_path: Some(PathBuf::from(r"localhost1.pem")),
tls_cert_key_path: Some(PathBuf::from(r"localhost1.pem")),
server_config: Mutex::new(None),
},
);
}