Skip to content

Commit e20034f

Browse files
committed
✨ feat: provide a path for the opensearch description file (#622)
1 parent d320c04 commit e20034f

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub async fn run(listener: TcpListener, config: &'static Config) -> tokio::io::R
111111
.service(routes::about) // about page
112112
.service(routes::settings) // settings page
113113
.service(routes::export_import::download) // download page
114+
.service(routes::opensearch_description) // opensearch description file
114115
.default_service(web::route().to(routes::not_found)) // error page
115116
})
116117
.workers(config.threads as usize)

src/routes/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
5252
.body(page_content))
5353
}
5454

55+
/// Handles the route of robots.txt page of the `websurfx` meta search engine website.
56+
#[get("/websurfx.xml")]
57+
pub async fn opensearch_description(
58+
_req: HttpRequest,
59+
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
60+
let page_content: String = read_to_string(format!(
61+
"{}/websurfx.xml",
62+
file_path(FileType::Theme).await?
63+
))
64+
.await?;
65+
let content_type = ContentType("application/opensearchdescription+xml".parse().unwrap());
66+
Ok(HttpResponse::Ok()
67+
.insert_header(content_type)
68+
.body(page_content))
69+
}
70+
5571
/// Handles the route of about page of the `websurfx` meta search engine website.
5672
#[get("/about")]
5773
pub async fn about(

0 commit comments

Comments
 (0)