add custom index
This commit is contained in:
parent
e4005b38ce
commit
0f35d34bcb
7 changed files with 291 additions and 268 deletions
507
Cargo.lock
generated
507
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
20
Cargo.toml
20
Cargo.toml
|
@ -1,15 +1,15 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mirrord"
|
name = "mirrord"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-files = "0.6.5"
|
actix-files = "0.6"
|
||||||
actix-web = "4.5.1"
|
actix-web = "4.5"
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11"
|
||||||
log = "0.4.21"
|
log = "0.4"
|
||||||
rand = "0.8.5"
|
rand = "0.8"
|
||||||
regex = "1.10.4"
|
regex = "1.10"
|
||||||
reqwest = "0.12.3"
|
reqwest = "0.12"
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "0.8.12"
|
toml = "0.8"
|
||||||
|
|
|
@ -7,3 +7,4 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
- ./sample.conf:/mirrord.conf
|
- ./sample.conf:/mirrord.conf
|
||||||
|
# - ./static/:/static # Custom Index
|
||||||
|
|
|
@ -18,3 +18,9 @@ no_cache = '.*(?:db|db\.sig)$'
|
||||||
|
|
||||||
# Redirect only paths matching this regex to the mirrors, return 404 otherwise
|
# Redirect only paths matching this regex to the mirrors, return 404 otherwise
|
||||||
only_allow = '^\/archlinux'
|
only_allow = '^\/archlinux'
|
||||||
|
|
||||||
|
# Show an index page on root path /
|
||||||
|
# Options:
|
||||||
|
# - `no` // disable index page
|
||||||
|
# - `<path>` // custom index page html file
|
||||||
|
index = "no"
|
||||||
|
|
|
@ -15,6 +15,8 @@ pub struct Config {
|
||||||
pub ttl: Option<usize>,
|
pub ttl: Option<usize>,
|
||||||
/// Regex for allowing only specific path requests
|
/// Regex for allowing only specific path requests
|
||||||
pub only_allow: Option<String>,
|
pub only_allow: Option<String>,
|
||||||
|
/// Index Page
|
||||||
|
pub index: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
|
@ -7,6 +7,12 @@ async fn index(req: HttpRequest) -> impl Responder {
|
||||||
let path = req.path();
|
let path = req.path();
|
||||||
let p: &actix_web::web::Data<Mirror> = req.app_data().unwrap();
|
let p: &actix_web::web::Data<Mirror> = req.app_data().unwrap();
|
||||||
|
|
||||||
|
if path == "/" {
|
||||||
|
if let Some(ret) = p.index_page() {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let data = p.get(path, &req).await;
|
let data = p.get(path, &req).await;
|
||||||
data.unwrap_or_else(|| HttpResponse::NotFound().finish())
|
data.unwrap_or_else(|| HttpResponse::NotFound().finish())
|
||||||
}
|
}
|
||||||
|
|
15
src/proxy.rs
15
src/proxy.rs
|
@ -203,6 +203,21 @@ impl Mirror {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn index_page(&self) -> Option<HttpResponse> {
|
||||||
|
if let Some(index) = &self.config.index {
|
||||||
|
return match index.as_str() {
|
||||||
|
"no" => None,
|
||||||
|
file => Some(
|
||||||
|
HttpResponse::Ok()
|
||||||
|
.content_type("text/html")
|
||||||
|
.body(std::fs::read_to_string(file).unwrap()),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Asynchronously fetches content from the specified URL and saves it to the provided file path.
|
/// Asynchronously fetches content from the specified URL and saves it to the provided file path.
|
||||||
///
|
///
|
||||||
/// This function sends an HTTP GET request to the URL specified by `path`, retrieves the response,
|
/// This function sends an HTTP GET request to the URL specified by `path`, retrieves the response,
|
||||||
|
|
Loading…
Add table
Reference in a new issue