mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Added optional minimal file server
This commit is contained in:
@@ -14,6 +14,8 @@ pub struct APIUpstreamProvider {
|
||||
pub tls_address: Option<String>,
|
||||
pub tls_certificate: Option<String>,
|
||||
pub tls_key_file: Option<String>,
|
||||
pub file_server_address: Option<String>,
|
||||
pub file_server_folder: Option<String>,
|
||||
}
|
||||
|
||||
pub struct ConsulProvider {
|
||||
|
||||
@@ -150,15 +150,5 @@ pub fn parce_main_config(path: &str) -> AppConfig {
|
||||
}
|
||||
}
|
||||
};
|
||||
// match cfo.config_tls_address.clone() {
|
||||
// Some(tls_cert) => {
|
||||
// if let Some((ip, port_str)) = tls_cert.split_once(':') {
|
||||
// if let Ok(port) = port_str.parse::<u16>() {
|
||||
// cfo.local_tls_server = Option::from((ip.to_string(), port));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// None => {}
|
||||
// };
|
||||
cfo
|
||||
}
|
||||
|
||||
@@ -75,4 +75,6 @@ pub struct AppConfig {
|
||||
pub proxy_port_tls: Option<u16>,
|
||||
pub local_server: Option<(String, u16)>,
|
||||
pub proxy_certificates: Option<String>,
|
||||
pub file_server_address: Option<String>,
|
||||
pub file_server_folder: Option<String>,
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ impl BackgroundService for LB {
|
||||
tls_address: self.config.config_tls_address.clone(),
|
||||
tls_certificate: self.config.config_tls_certificate.clone(),
|
||||
tls_key_file: self.config.config_tls_key_file.clone(),
|
||||
file_server_address: self.config.file_server_address.clone(),
|
||||
file_server_folder: self.config.file_server_folder.clone(),
|
||||
};
|
||||
let tx_api = tx.clone();
|
||||
let _ = tokio::spawn(async move { api_load.start(tx_api).await });
|
||||
|
||||
@@ -79,26 +79,6 @@ impl ProxyHttp for LB {
|
||||
match ddr {
|
||||
Some((address, port, ssl, is_h2, to_https)) => {
|
||||
let mut peer = Box::new(HttpPeer::new((address.clone(), port.clone()), ssl, String::new()));
|
||||
/*
|
||||
let key = PeerKey {
|
||||
addr: address.clone(),
|
||||
port: port,
|
||||
ssl: ssl,
|
||||
};
|
||||
|
||||
let gk = key.get_hash();
|
||||
let pooled_conn = self.connection_pool.connections.get(&gk);
|
||||
match pooled_conn {
|
||||
Some(conn) => {
|
||||
peer = Box::from(conn);
|
||||
}
|
||||
None => {
|
||||
let id = self.connection_pool.next_id();
|
||||
self.connection_pool.connections.put(&ConnectionMeta { key: gk, id: id }, *peer.clone());
|
||||
debug!("Added peer to pool: {}", id);
|
||||
}
|
||||
}
|
||||
*/
|
||||
// if session.is_http2() {
|
||||
if is_h2 {
|
||||
peer.options.alpn = ALPN::H2;
|
||||
@@ -125,11 +105,6 @@ impl ProxyHttp for LB {
|
||||
}
|
||||
|
||||
ctx.backend_id = format!("{}:{}:{}", address.clone(), port.clone(), ssl);
|
||||
/*
|
||||
ctx.peer = Some(peer.clone());
|
||||
ctx.peer_key = Some(key.clone());
|
||||
ctx.group_key = Some(gk.clone());
|
||||
*/
|
||||
Ok(peer)
|
||||
}
|
||||
None => {
|
||||
|
||||
@@ -17,6 +17,7 @@ use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct InputKey {
|
||||
@@ -42,12 +43,14 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
||||
master_key: config.masterkey.clone(),
|
||||
config_sender: to_return.clone(),
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
// .route("/{*wildcard}", get(senderror))
|
||||
// .route("/{*wildcard}", post(senderror))
|
||||
// .route("/{*wildcard}", put(senderror))
|
||||
// .route("/{*wildcard}", head(senderror))
|
||||
// .route("/{*wildcard}", delete(senderror))
|
||||
// .nest_service("/static", static_files)
|
||||
.route("/jwt", post(jwt_gen))
|
||||
.route("/conf", post(conf))
|
||||
.route("/metrics", get(metrics))
|
||||
@@ -65,6 +68,13 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
||||
info!("Starting the TLS API server on: {}", value);
|
||||
}
|
||||
|
||||
if let (Some(address), Some(folder)) = (&config.file_server_address, &config.file_server_folder) {
|
||||
let static_files = ServeDir::new(folder);
|
||||
let static_serve: Router = Router::new().fallback_service(static_files);
|
||||
let static_listen = TcpListener::bind(address).await.unwrap();
|
||||
let _ = tokio::spawn(async move { axum::serve(static_listen, static_serve).await.unwrap() });
|
||||
}
|
||||
|
||||
let listener = TcpListener::bind(config.address.clone()).await.unwrap();
|
||||
info!("Starting the API server on: {}", config.address);
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user