diff --git a/dns/src/gurt_server.rs b/dns/src/gurt_server.rs index 473dbb4..8c7695a 100644 --- a/dns/src/gurt_server.rs +++ b/dns/src/gurt_server.rs @@ -129,7 +129,7 @@ impl GurtHandler for AppHandler { log::info!("Handler started for {} {} from {}", ctx.method(), ctx.path(), ctx.remote_addr); let result = match handler_type { - HandlerType::Index => routes::index(app_state).await, + HandlerType::Index => routes::index(&ctx, app_state).await, HandlerType::GetDomain => { if ctx.path().contains("/records") { handle_authenticated!(ctx, app_state, routes::get_domain_records) diff --git a/dns/src/gurt_server/routes.rs b/dns/src/gurt_server/routes.rs index 043b2c3..3801c94 100644 --- a/dns/src/gurt_server/routes.rs +++ b/dns/src/gurt_server/routes.rs @@ -20,11 +20,28 @@ fn parse_query_string(query: &str) -> HashMap { params } -pub(crate) async fn index(_app_state: AppState) -> Result { +pub(crate) async fn index(ctx: &ServerContext, _app_state: AppState) -> Result { + let host_header = ctx.request.headers().get("host") + .and_then(|h| h.to_str().ok()) + .unwrap_or(""); + + let hostname = host_header.split(':').next().unwrap_or(host_header); + + log::info!("Index handler - Host header: '{}', hostname: '{}'", host_header, hostname); + let current_dir = std::env::current_dir() .map_err(|_| GurtError::invalid_message("Failed to get current directory"))?; - let frontend_dir = current_dir.join("frontend"); - let index_path = frontend_dir.join("index.html"); + + let (frontend_dir, file_name) = if hostname == "search.web" { + log::info!("Index handler serving search.html for search.web domain"); + (current_dir.join("search-engine").join("frontend"), "search.html") + } else { + log::info!("Index handler serving index.html for domain: '{}'", hostname); + (current_dir.join("frontend"), "index.html") + }; + + let index_path = frontend_dir.join(file_name); + log::info!("Index handler attempting to read: '{}'", index_path.display()); match tokio::fs::read_to_string(&index_path).await { Ok(content) => {