wip: refactor whole module in lib
This commit is contained in:
parent
7bc6e30935
commit
f98c778a0c
42 changed files with 943 additions and 531 deletions
|
|
@ -1,19 +1,11 @@
|
|||
mod backend;
|
||||
mod certs;
|
||||
mod constants;
|
||||
mod error;
|
||||
mod globals;
|
||||
mod handler;
|
||||
mod hyper_executor;
|
||||
mod log;
|
||||
mod proxy;
|
||||
mod utils;
|
||||
|
||||
use crate::{error::*, globals::Globals, handler::HttpMessageHandlerBuilder, log::*, proxy::ProxyBuilder};
|
||||
use futures::future::select_all;
|
||||
use hyper_executor::build_http_server;
|
||||
// use hyper_trust_dns::TrustDnsResolver;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use crate::{error::*, log::*};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use crate::{
|
||||
certs::{CertsAndKeys, CryptoSource},
|
||||
|
|
@ -66,48 +58,48 @@ where
|
|||
info!("Cache is disabled")
|
||||
}
|
||||
|
||||
// build global
|
||||
let globals = Arc::new(Globals {
|
||||
proxy_config: proxy_config.clone(),
|
||||
backends: app_config_list.clone().try_into()?,
|
||||
request_count: Default::default(),
|
||||
runtime_handle: runtime_handle.clone(),
|
||||
term_notify: term_notify.clone(),
|
||||
});
|
||||
// // build global
|
||||
// let globals = Arc::new(Globals {
|
||||
// proxy_config: proxy_config.clone(),
|
||||
// backends: app_config_list.clone().try_into()?,
|
||||
// request_count: Default::default(),
|
||||
// runtime_handle: runtime_handle.clone(),
|
||||
// term_notify: term_notify.clone(),
|
||||
// });
|
||||
|
||||
// build message handler including a request forwarder
|
||||
let msg_handler = Arc::new(
|
||||
HttpMessageHandlerBuilder::default()
|
||||
// .forwarder(Arc::new(Forwarder::new(&globals).await))
|
||||
.globals(globals.clone())
|
||||
.build()?,
|
||||
);
|
||||
// // build message handler including a request forwarder
|
||||
// let msg_handler = Arc::new(
|
||||
// HttpMessageHandlerBuilder::default()
|
||||
// // .forwarder(Arc::new(Forwarder::new(&globals).await))
|
||||
// .globals(globals.clone())
|
||||
// .build()?,
|
||||
// );
|
||||
|
||||
let http_server = Arc::new(build_http_server(&globals));
|
||||
// let http_server = Arc::new(build_http_server(&globals));
|
||||
|
||||
let addresses = globals.proxy_config.listen_sockets.clone();
|
||||
let futures = select_all(addresses.into_iter().map(|addr| {
|
||||
let mut tls_enabled = false;
|
||||
if let Some(https_port) = globals.proxy_config.https_port {
|
||||
tls_enabled = https_port == addr.port()
|
||||
}
|
||||
// let addresses = globals.proxy_config.listen_sockets.clone();
|
||||
// let futures = select_all(addresses.into_iter().map(|addr| {
|
||||
// let mut tls_enabled = false;
|
||||
// if let Some(https_port) = globals.proxy_config.https_port {
|
||||
// tls_enabled = https_port == addr.port()
|
||||
// }
|
||||
|
||||
let proxy = ProxyBuilder::default()
|
||||
.globals(globals.clone())
|
||||
.listening_on(addr)
|
||||
.tls_enabled(tls_enabled)
|
||||
.http_server(http_server.clone())
|
||||
.msg_handler(msg_handler.clone())
|
||||
.build()
|
||||
.unwrap();
|
||||
// let proxy = ProxyBuilder::default()
|
||||
// .globals(globals.clone())
|
||||
// .listening_on(addr)
|
||||
// .tls_enabled(tls_enabled)
|
||||
// .http_server(http_server.clone())
|
||||
// .msg_handler(msg_handler.clone())
|
||||
// .build()
|
||||
// .unwrap();
|
||||
|
||||
globals.runtime_handle.spawn(async move { proxy.start().await })
|
||||
}));
|
||||
// globals.runtime_handle.spawn(async move { proxy.start().await })
|
||||
// }));
|
||||
|
||||
// wait for all future
|
||||
if let (Ok(Err(e)), _, _) = futures.await {
|
||||
error!("Some proxy services are down: {}", e);
|
||||
};
|
||||
// // wait for all future
|
||||
// if let (Ok(Err(e)), _, _) = futures.await {
|
||||
// error!("Some proxy services are down: {}", e);
|
||||
// };
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue