mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 03:46:37 +00:00
add console static server
This commit is contained in:
Generated
+20
@@ -1419,6 +1419,25 @@ dependencies = [
|
|||||||
"icu_properties",
|
"icu_properties",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "include_dir"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd"
|
||||||
|
dependencies = [
|
||||||
|
"include_dir_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "include_dir_macros"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.3"
|
version = "1.9.3"
|
||||||
@@ -2406,6 +2425,7 @@ dependencies = [
|
|||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"iam",
|
"iam",
|
||||||
|
"include_dir",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lock",
|
"lock",
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ crypto = { path = "../crypto" }
|
|||||||
iam = { path = "../iam" }
|
iam = { path = "../iam" }
|
||||||
jsonwebtoken = "9.3.0"
|
jsonwebtoken = "9.3.0"
|
||||||
tower-http = { version = "0.6.2", features = ["cors"] }
|
tower-http = { version = "0.6.2", features = ["cors"] }
|
||||||
|
include_dir = "0.7.4"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build.workspace = true
|
prost-build.workspace = true
|
||||||
|
|||||||
@@ -53,4 +53,7 @@ pub struct Opt {
|
|||||||
/// Domain name used for virtual-hosted-style requests.
|
/// Domain name used for virtual-hosted-style requests.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub domain_name: Option<String>,
|
pub domain_name: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long, default_value_t = format!("0.0.0.0:{}", 0))]
|
||||||
|
pub console_address: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
use axum::{
|
||||||
|
body::Body,
|
||||||
|
http::{Response, StatusCode},
|
||||||
|
response::IntoResponse,
|
||||||
|
routing::get,
|
||||||
|
Router,
|
||||||
|
};
|
||||||
|
|
||||||
|
use include_dir::{include_dir, Dir};
|
||||||
|
|
||||||
|
static STATIC_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/static");
|
||||||
|
|
||||||
|
async fn static_handler(uri: axum::http::Uri) -> impl IntoResponse {
|
||||||
|
let path = uri.path().trim_start_matches('/');
|
||||||
|
if let Some(file) = STATIC_DIR.get_file(path) {
|
||||||
|
Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.body(Body::from(file.contents()))
|
||||||
|
.unwrap()
|
||||||
|
} else {
|
||||||
|
Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.body(Body::from("404 Not Found"))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_static_file_server(addrs: &str) {
|
||||||
|
// 创建路由
|
||||||
|
let app = Router::new().route("/*file", get(static_handler));
|
||||||
|
|
||||||
|
let listener = tokio::net::TcpListener::bind(addrs).await.unwrap();
|
||||||
|
|
||||||
|
println!("console listening on: {}", listener.local_addr().unwrap());
|
||||||
|
|
||||||
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
}
|
||||||
+6
-1
@@ -1,6 +1,7 @@
|
|||||||
mod admin;
|
mod admin;
|
||||||
mod auth;
|
mod auth;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod console;
|
||||||
mod grpc;
|
mod grpc;
|
||||||
mod service;
|
mod service;
|
||||||
mod storage;
|
mod storage;
|
||||||
@@ -176,7 +177,7 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
let http_server = ConnBuilder::new(TokioExecutor::new());
|
let http_server = ConnBuilder::new(TokioExecutor::new());
|
||||||
let mut ctrl_c = std::pin::pin!(tokio::signal::ctrl_c());
|
let mut ctrl_c = std::pin::pin!(tokio::signal::ctrl_c());
|
||||||
let graceful = hyper_util::server::graceful::GracefulShutdown::new();
|
let graceful = hyper_util::server::graceful::GracefulShutdown::new();
|
||||||
info!("server is running at http://{local_addr}");
|
println!("server is running at http://{local_addr}");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (socket, _) = tokio::select! {
|
let (socket, _) = tokio::select! {
|
||||||
@@ -239,6 +240,10 @@ async fn run(opt: config::Opt) -> Result<()> {
|
|||||||
|
|
||||||
info!("server was started");
|
info!("server was started");
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
console::start_static_file_server(&opt.console_address).await;
|
||||||
|
});
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = tokio::signal::ctrl_c() => {
|
_ = tokio::signal::ctrl_c() => {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
static index
|
||||||
+4
-4
@@ -10,13 +10,13 @@ mkdir -p ./target/volume/test
|
|||||||
mkdir -p ./target/volume/test{0..4}
|
mkdir -p ./target/volume/test{0..4}
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$RUST_LOG" ]; then
|
# if [ -z "$RUST_LOG" ]; then
|
||||||
export RUST_LOG="rustfs=debug,ecstore=debug,s3s=debug,iam=debug"
|
# export RUST_LOG="rustfs=debug,ecstore=debug,s3s=debug,iam=debug"
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# export RUSTFS_ERASURE_SET_DRIVE_COUNT=5
|
# export RUSTFS_ERASURE_SET_DRIVE_COUNT=5
|
||||||
|
|
||||||
export RUSTFS_STORAGE_CLASS_INLINE_BLOCK="512 KB"
|
# export RUSTFS_STORAGE_CLASS_INLINE_BLOCK="512 KB"
|
||||||
|
|
||||||
|
|
||||||
# DATA_DIR_ARG="./target/volume/test{0...4}"
|
# DATA_DIR_ARG="./target/volume/test{0...4}"
|
||||||
|
|||||||
Reference in New Issue
Block a user