mirror of
https://github.com/storytold/voder-proxy.git
synced 2026-10-19 07:43:12 +00:00
add proxy_configs.toml (unread currently)
This commit is contained in:
Generated
+64
@@ -445,12 +445,30 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.56"
|
||||
@@ -505,6 +523,23 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.2"
|
||||
@@ -529,6 +564,17 @@ dependencies = [
|
||||
"bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.0"
|
||||
@@ -689,6 +735,15 @@ dependencies = [
|
||||
"tokio-executor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.2"
|
||||
@@ -705,6 +760,9 @@ dependencies = [
|
||||
"hyper",
|
||||
"hyper-reverse-proxy",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -716,6 +774,12 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.2"
|
||||
|
||||
+3
-2
@@ -16,8 +16,9 @@ path = "src/main.rs"
|
||||
anyhow = "1.0.31"
|
||||
env_logger = "0.7.1"
|
||||
futures = "0.1"
|
||||
#hyper = "0.13.6"
|
||||
hyper = "0.12"
|
||||
hyper-reverse-proxy = "0.4"
|
||||
log = "0.4.8"
|
||||
#simple_proxy = "1.3.1"
|
||||
serde = "1.0.104"
|
||||
serde_derive = "1.0.104"
|
||||
toml = "0.5.6"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[backends]]
|
||||
voice = "foo"
|
||||
ip = "127.0.0.1"
|
||||
port = "12345"
|
||||
|
||||
[[backends]]
|
||||
voice = "bar"
|
||||
ip = "1.1.1.1"
|
||||
port = "12345"
|
||||
+47
-1
@@ -1,4 +1,5 @@
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
|
||||
/*#[derive(Deserialize)]
|
||||
@@ -13,15 +14,40 @@ use futures::future::{self, Future};
|
||||
use hyper::server::conn::AddrStream;
|
||||
use hyper::service::{service_fn, make_service_fn};
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
use anyhow::Result as AnyhowResult;
|
||||
use std::env;
|
||||
|
||||
type BoxFut = Box<Future<Item=Response<Body>, Error=hyper::Error> + Send>;
|
||||
|
||||
const ENV_PROXY_CONFIG_FILE : &'static str = "PROXY_CONFIG_FILE";
|
||||
const ENV_ROUTE_ONE : &'static str = "ROUTE_ONE";
|
||||
const ENV_ROUTE_TWO : &'static str = "ROUTE_TWO";
|
||||
const ENV_RUST_LOG : &'static str = "RUST_LOG";
|
||||
|
||||
const ROUTE_ONE_DEFAULT : &'static str = "http://127.0.0.1:12345";
|
||||
const ROUTE_TWO_DEFAULT : &'static str = "http://127.0.0.1:3000";
|
||||
const DEFAULT_PROXY_CONFIG_FILE : &'static str = "proxy_configs.toml";
|
||||
const DEFAULT_RUST_LOG: &'static str = "debug";
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct ProxyConfigs {
|
||||
pub backends: Vec<ProxyConfig>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct ProxyConfig {
|
||||
pub voice : String,
|
||||
pub ip: String,
|
||||
pub port: String,
|
||||
}
|
||||
|
||||
impl ProxyConfigs {
|
||||
pub fn load_from_file(filename: &str) -> AnyhowResult<Self> {
|
||||
let contents = std::fs::read_to_string(filename)?;
|
||||
let configs = toml::from_str(&contents)?;
|
||||
Ok(configs)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_env_string(env_name: &str, default: &str) -> String {
|
||||
match env::var(env_name).as_ref().ok() {
|
||||
@@ -39,13 +65,31 @@ fn debug_request(req: Request<Body>) -> BoxFut {
|
||||
Box::new(future::ok(response))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> AnyhowResult<()> {
|
||||
if env::var(ENV_RUST_LOG)
|
||||
.as_ref()
|
||||
.ok()
|
||||
.is_none()
|
||||
{
|
||||
println!("Setting default logging level to \"{}\", override with env var {}.",
|
||||
DEFAULT_RUST_LOG, ENV_RUST_LOG);
|
||||
std::env::set_var(ENV_RUST_LOG, DEFAULT_RUST_LOG);
|
||||
}
|
||||
|
||||
env_logger::init();
|
||||
|
||||
let route_one = get_env_string(ENV_ROUTE_ONE, ROUTE_ONE_DEFAULT);
|
||||
let route_two = get_env_string(ENV_ROUTE_TWO, ROUTE_TWO_DEFAULT);
|
||||
|
||||
info!("Route one: {}", route_one);
|
||||
info!("Route two: {}", route_two);
|
||||
|
||||
let proxy_configs_file = get_env_string(ENV_PROXY_CONFIG_FILE, DEFAULT_PROXY_CONFIG_FILE);
|
||||
info!("Proxy config file: {}", proxy_configs_file);
|
||||
|
||||
let proxy_configs = ProxyConfigs::load_from_file(&proxy_configs_file)?;
|
||||
info!("Proxy configs: {:?}", proxy_configs);
|
||||
|
||||
// This is our socket address...
|
||||
let addr = ([127, 0, 0, 1], 13900).into();
|
||||
|
||||
@@ -77,4 +121,6 @@ fn main() {
|
||||
|
||||
// Run this server for... forever!
|
||||
hyper::rt::run(server);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user