add s3s host style

This commit is contained in:
weisd
2025-02-26 17:35:31 +08:00
parent b5ebc90667
commit 3b56bb69e6
3 changed files with 16 additions and 5 deletions

View File

@@ -42,8 +42,8 @@ pub struct Opt {
#[arg(long, default_value_t = format!("0.0.0.0:{}", DEFAULT_PORT), env = "RUSTFS_ADDRESS")]
pub address: String,
#[arg(long, default_value_t = format!("http://localhost:{}", DEFAULT_PORT), env = "RUSTFS_SERVER_ENDPOINT")]
pub server_endpoint: String,
#[arg(long, env = "RUSTFS_SERVER_DOMAINS")]
pub server_domains: Vec<String>,
/// Access key used for authentication.
#[arg(long, default_value_t = DEFAULT_ACCESS_KEY.to_string(), env = "RUSTFS_ACCESS_KEY")]

View File

@@ -29,7 +29,7 @@ use hyper_util::{
};
use iam::init_iam_sys;
use protos::proto_gen::node_service::node_service_server::NodeServiceServer;
use s3s::service::S3ServiceBuilder;
use s3s::{host::MultiDomain, service::S3ServiceBuilder};
use service::hybrid;
use std::{io::IsTerminal, net::SocketAddr};
use tokio::net::TcpListener;
@@ -137,6 +137,11 @@ async fn run(opt: config::Opt) -> Result<()> {
b.set_route(admin::make_admin_route()?);
if !opt.server_domains.is_empty() {
info!("virtual-hosted-style requests are enabled use domain_name {:?}", &opt.server_domains);
b.set_host(MultiDomain::new(&opt.server_domains)?);
}
// // Enable parsing virtual-hosted-style requests
// if let Some(dm) = opt.domain_name {
// info!("virtual-hosted-style requests are enabled use domain_name {}", &dm);
@@ -234,7 +239,13 @@ async fn run(opt: config::Opt) -> Result<()> {
if opt.console_enable {
info!("console is enabled");
tokio::spawn(async move {
console::start_static_file_server(&opt.console_address, &opt.server_endpoint).await;
let ep = if !opt.server_domains.is_empty() {
format!("http://{}", opt.server_domains[0].clone())
} else {
format!("http://127.0.0.1:{}", server_port)
};
console::start_static_file_server(&opt.console_address, &ep).await;
});
}

View File

@@ -24,7 +24,7 @@ export RUSTFS_VOLUMES="./target/volume/test"
export RUSTFS_ADDRESS="0.0.0.0:9000"
export RUSTFS_CONSOLE_ENABLE=true
export RUSTFS_CONSOLE_ADDRESS="0.0.0.0:9002"
export RUSTFS_SERVER_ENDPOINT="http://localhost:9000"
# export RUSTFS_SERVER_DOMAINS="localhost:9000"
if [ -n "$1" ]; then
export RUSTFS_VOLUMES="$1"