mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
Added optional minimal file server
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -141,6 +141,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tonic",
|
"tonic",
|
||||||
|
"tower-http",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
"x509-parser",
|
"x509-parser",
|
||||||
]
|
]
|
||||||
@@ -1078,6 +1079,12 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http-range-header"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "httparse"
|
name = "httparse"
|
||||||
version = "1.9.5"
|
version = "1.9.5"
|
||||||
@@ -1617,6 +1624,16 @@ version = "0.3.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mime_guess"
|
||||||
|
version = "2.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
|
||||||
|
dependencies = [
|
||||||
|
"mime",
|
||||||
|
"unicase",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "minimal-lexical"
|
name = "minimal-lexical"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -3167,14 +3184,24 @@ checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.8.0",
|
"bitflags 2.8.0",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
|
"http-range-header",
|
||||||
|
"httpdate",
|
||||||
"iri-string",
|
"iri-string",
|
||||||
|
"mime",
|
||||||
|
"mime_guess",
|
||||||
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -47,4 +47,6 @@ lazy_static = "1.5.0"
|
|||||||
#openssl = "0.10.73"
|
#openssl = "0.10.73"
|
||||||
x509-parser = "0.17.0"
|
x509-parser = "0.17.0"
|
||||||
rustls-pemfile = "2.2.0"
|
rustls-pemfile = "2.2.0"
|
||||||
|
tower-http = { version = "0.6.6", features = ["fs"] }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ Built on Rust, on top of **Cloudflare’s Pingora engine**, **Aralez** delivers
|
|||||||
| **hc_method** | HEAD | Healthcheck method (HEAD, GET, POST are supported) UPPERCASE |
|
| **hc_method** | HEAD | Healthcheck method (HEAD, GET, POST are supported) UPPERCASE |
|
||||||
| **hc_interval** | 2 | Interval for health checks in seconds |
|
| **hc_interval** | 2 | Interval for health checks in seconds |
|
||||||
| **master_key** | 5aeff7f9-7b94-447c-af60-e8c488544a3e | Master key for working with API server and JWT Secret generation |
|
| **master_key** | 5aeff7f9-7b94-447c-af60-e8c488544a3e | Master key for working with API server and JWT Secret generation |
|
||||||
|
| **file_server_folder** | /some/local/folder | Optional, local folder to serve |
|
||||||
|
| **file_server_address** | 127.0.0.1:3002 | Optional, Local address for file server. Can set as upstream for public access |
|
||||||
|
|
||||||
### 🌐 `upstreams.yaml`
|
### 🌐 `upstreams.yaml`
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Main configuration file , applied on startup
|
# Main configuration file , applied on startup
|
||||||
threads: 12 # Nubber of daemon threads default setting
|
threads: 12 # Nubber of daemon threads default setting
|
||||||
#user: pastor # Username for running aralez after dropping root privileges, requires program to start as root
|
#user: aralez # Username for running aralez after dropping root privileges, requires program to start as root
|
||||||
#group: pastor # Group for running aralez after dropping root privileges, requires program to start as root
|
#group: aralez # Group for running aralez after dropping root privileges, requires program to start as root
|
||||||
daemon: false # Run in background
|
daemon: false # Run in background
|
||||||
upstream_keepalive_pool_size: 500 # Pool size for upstream keepalive connections
|
upstream_keepalive_pool_size: 500 # Pool size for upstream keepalive connections
|
||||||
pid_file: /tmp/aralez.pid # Path to PID file
|
pid_file: /tmp/aralez.pid # Path to PID file
|
||||||
@@ -13,8 +13,10 @@ config_tls_certificate: etc/server.crt # Mandatory if config_tls_address is set
|
|||||||
config_tls_key_file: etc/key.pem # Mandatory if config_tls_address is set
|
config_tls_key_file: etc/key.pem # Mandatory if config_tls_address is set
|
||||||
proxy_address_http: 0.0.0.0:6193 # Proxy HTTP bind address
|
proxy_address_http: 0.0.0.0:6193 # Proxy HTTP bind address
|
||||||
proxy_address_tls: 0.0.0.0:6194 # Optional, Proxy TLS bind address
|
proxy_address_tls: 0.0.0.0:6194 # Optional, Proxy TLS bind address
|
||||||
proxy_certificates: etc/yoyo # Mandatory if proxy_address_tls set, should contain certificate and key files strictly in a format {NAME}.crt, {NAME}.key.
|
proxy_certificates: etc/certificates # Mandatory if proxy_address_tls set, should contain certificate and key files strictly in a format {NAME}.crt, {NAME}.key.
|
||||||
upstreams_conf: etc/upstreams.yaml # the location of upstreams file
|
upstreams_conf: etc/upstreams.yaml # the location of upstreams file
|
||||||
|
#file_server_folder: /some/path # Optional, local folder to serve
|
||||||
|
#file_server_address: 127.0.0.1:3002 # Optional, Local address for file server. Can set as upstream for public access.
|
||||||
log_level: info # info, warn, error, debug, trace, off
|
log_level: info # info, warn, error, debug, trace, off
|
||||||
hc_method: HEAD # Healthcheck method (HEAD, GET, POST are supported) UPPERCASE
|
hc_method: HEAD # Healthcheck method (HEAD, GET, POST are supported) UPPERCASE
|
||||||
hc_interval: 2 #Interval for health checks in seconds
|
hc_interval: 2 #Interval for health checks in seconds
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ pub struct APIUpstreamProvider {
|
|||||||
pub tls_address: Option<String>,
|
pub tls_address: Option<String>,
|
||||||
pub tls_certificate: Option<String>,
|
pub tls_certificate: Option<String>,
|
||||||
pub tls_key_file: Option<String>,
|
pub tls_key_file: Option<String>,
|
||||||
|
pub file_server_address: Option<String>,
|
||||||
|
pub file_server_folder: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ConsulProvider {
|
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
|
cfo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,4 +75,6 @@ pub struct AppConfig {
|
|||||||
pub proxy_port_tls: Option<u16>,
|
pub proxy_port_tls: Option<u16>,
|
||||||
pub local_server: Option<(String, u16)>,
|
pub local_server: Option<(String, u16)>,
|
||||||
pub proxy_certificates: Option<String>,
|
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_address: self.config.config_tls_address.clone(),
|
||||||
tls_certificate: self.config.config_tls_certificate.clone(),
|
tls_certificate: self.config.config_tls_certificate.clone(),
|
||||||
tls_key_file: self.config.config_tls_key_file.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 tx_api = tx.clone();
|
||||||
let _ = tokio::spawn(async move { api_load.start(tx_api).await });
|
let _ = tokio::spawn(async move { api_load.start(tx_api).await });
|
||||||
|
|||||||
@@ -79,26 +79,6 @@ impl ProxyHttp for LB {
|
|||||||
match ddr {
|
match ddr {
|
||||||
Some((address, port, ssl, is_h2, to_https)) => {
|
Some((address, port, ssl, is_h2, to_https)) => {
|
||||||
let mut peer = Box::new(HttpPeer::new((address.clone(), port.clone()), ssl, String::new()));
|
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 session.is_http2() {
|
||||||
if is_h2 {
|
if is_h2 {
|
||||||
peer.options.alpn = ALPN::H2;
|
peer.options.alpn = ALPN::H2;
|
||||||
@@ -125,11 +105,6 @@ impl ProxyHttp for LB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.backend_id = format!("{}:{}:{}", address.clone(), port.clone(), ssl);
|
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)
|
Ok(peer)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use std::collections::HashMap;
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct InputKey {
|
struct InputKey {
|
||||||
@@ -42,12 +43,14 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
|||||||
master_key: config.masterkey.clone(),
|
master_key: config.masterkey.clone(),
|
||||||
config_sender: to_return.clone(),
|
config_sender: to_return.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
// .route("/{*wildcard}", get(senderror))
|
// .route("/{*wildcard}", get(senderror))
|
||||||
// .route("/{*wildcard}", post(senderror))
|
// .route("/{*wildcard}", post(senderror))
|
||||||
// .route("/{*wildcard}", put(senderror))
|
// .route("/{*wildcard}", put(senderror))
|
||||||
// .route("/{*wildcard}", head(senderror))
|
// .route("/{*wildcard}", head(senderror))
|
||||||
// .route("/{*wildcard}", delete(senderror))
|
// .route("/{*wildcard}", delete(senderror))
|
||||||
|
// .nest_service("/static", static_files)
|
||||||
.route("/jwt", post(jwt_gen))
|
.route("/jwt", post(jwt_gen))
|
||||||
.route("/conf", post(conf))
|
.route("/conf", post(conf))
|
||||||
.route("/metrics", get(metrics))
|
.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);
|
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();
|
let listener = TcpListener::bind(config.address.clone()).await.unwrap();
|
||||||
info!("Starting the API server on: {}", config.address);
|
info!("Starting the API server on: {}", config.address);
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user