add custom index
This commit is contained in:
parent
e4005b38ce
commit
0f35d34bcb
7 changed files with 291 additions and 268 deletions
|
@ -15,6 +15,8 @@ pub struct Config {
|
|||
pub ttl: Option<usize>,
|
||||
/// Regex for allowing only specific path requests
|
||||
pub only_allow: Option<String>,
|
||||
/// Index Page
|
||||
pub index: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
|
|
@ -7,6 +7,12 @@ async fn index(req: HttpRequest) -> impl Responder {
|
|||
let path = req.path();
|
||||
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;
|
||||
data.unwrap_or_else(|| HttpResponse::NotFound().finish())
|
||||
}
|
||||
|
|
15
src/proxy.rs
15
src/proxy.rs
|
@ -203,6 +203,21 @@ impl Mirror {
|
|||
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.
|
||||
///
|
||||
/// This function sends an HTTP GET request to the URL specified by `path`, retrieves the response,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue