-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add robots.txt and sitemap.xml (DEV-3931) (#152)
- Loading branch information
Showing
21 changed files
with
121 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use tracing::trace; | ||
|
||
pub(crate) async fn health_handler() -> &'static str { | ||
pub(crate) async fn health() -> &'static str { | ||
trace!("entered health_handler()"); | ||
"healthy" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod health; | ||
pub mod project_metadata_handler; | ||
pub mod robots_txt; | ||
pub mod sitemap_xml; | ||
pub mod v1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::extract::State; | ||
use axum::http::{Response, StatusCode}; | ||
|
||
use crate::app_state::AppState; | ||
use crate::error::DspMetaError; | ||
|
||
pub async fn robots_txt( | ||
State(state): State<Arc<AppState>>, | ||
) -> Result<Response<String>, DspMetaError> { | ||
let sitemap_xml = state | ||
.base_url | ||
.join("sitemap.xml") | ||
.expect("valid url") | ||
.to_string(); | ||
let response = Response::builder() | ||
.status(StatusCode::OK) | ||
.header("Content-Type", "text/plain") | ||
.body(format!( | ||
"Sitemap: {}\nUser-agent: *\nDisallow:\n", | ||
sitemap_xml | ||
)) | ||
.expect("Failed to build response"); | ||
Ok(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::extract::State; | ||
use axum::http::StatusCode; | ||
use axum::response::Response; | ||
use tracing::instrument; | ||
|
||
use crate::app_state::AppState; | ||
use crate::domain::service::project_metadata_api_contract::ProjectMetadataApiContract; | ||
use crate::error::DspMetaError; | ||
|
||
#[instrument(skip(state))] | ||
pub async fn sitemap_xml( | ||
State(state): State<Arc<AppState>>, | ||
) -> Result<Response<String>, DspMetaError> { | ||
let base_url = state.base_url.clone(); | ||
let mut xml = String::from("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); | ||
xml.push_str("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"); | ||
xml.push_str( | ||
format!( | ||
"<url><loc>{}</loc><changefreq>weekly</changefreq></url>\n", | ||
base_url | ||
) | ||
.as_str(), | ||
); | ||
for meta in state.project_metadata_service.find_all()? { | ||
let mut url = base_url.to_string() + "projects/"; | ||
url.push_str(&meta.project.shortcode.as_string()); | ||
let line = format!( | ||
"<url><loc>{}</loc><changefreq>weekly</changefreq></url>\n", | ||
url | ||
); | ||
xml.push_str(line.as_str()); | ||
} | ||
xml.push_str("</urlset>\n"); | ||
|
||
let resp = Response::builder() | ||
.status(StatusCode::OK) | ||
.header("Content-Type", "application/xml") | ||
.body(xml) | ||
.expect("Failed to build response"); | ||
Ok(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod projects; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod handlers; | ||
pub mod responses; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod convert; | ||
mod handler; | ||
mod model; | ||
pub mod router; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters