Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links in API about pages with subfolder #476

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/services/about.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Templates for "about" static pages.
use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX;

#[must_use]
pub fn index_page() -> String {
Expand All @@ -8,8 +7,7 @@ pub fn index_page() -> String {

#[must_use]
pub fn page() -> String {
format!(
r#"
r#"
<html>
<head>
<title>About</title>
Expand All @@ -22,17 +20,16 @@ pub fn page() -> String {
<p>Hi! This is a running <a href="https://github.com/torrust/torrust-index">torrust-index</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/{API_VERSION_URL_PREFIX}/about/license">license</a>
<a href="./about/license">license</a>
</footer>
</html>
"#
)
.to_string()
}

#[must_use]
pub fn license_page() -> String {
format!(
r#"
r#"
<html>
<head>
<title>Licensing</title>
Expand All @@ -55,9 +52,8 @@ pub fn license_page() -> String {
<p>If you want to read more about all the licenses and how they apply please refer to the <a href="https://github.com/torrust/torrust-index/blob/develop/licensing/contributor_agreement_v01.md">contributor agreement</a>.</p>
</body>
<footer style="padding: 1.25em 0;border-top: dotted 1px;">
<a href="/{API_VERSION_URL_PREFIX}/about">about</a>
<a href="../about">about</a>
</footer>
</html>
"#
)
"#.to_string()
}
2 changes: 1 addition & 1 deletion src/web/api/server/v1/contexts/about/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! <p>Hi! This is a running <a href="https://github.com/torrust/torrust-index">torrust-index</a>.</p>
//! </body>
//! <footer style="padding: 1.25em 0; border-top: dotted 1px;">
//! <a href="/v1/about/license">license</a>
//! <a href="v1/about/license">license</a>
//! </footer>
//! </html>
//! ```
Expand Down
10 changes: 7 additions & 3 deletions src/web/api/server/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::env;
use std::sync::Arc;

use axum::extract::DefaultBodyLimit;
use axum::response::Redirect;
use axum::routing::get;
use axum::{Json, Router};
use serde_json::{json, Value};
use tower_http::compression::CompressionLayer;
use tower_http::cors::CorsLayer;

use super::contexts::about::handlers::about_page_handler;
use super::contexts::{about, category, proxy, settings, tag, torrent, user};
use crate::bootstrap::config::ENV_VAR_CORS_PERMISSIVE;
use crate::common::AppData;
Expand All @@ -23,7 +23,7 @@ pub fn router(app_data: Arc<AppData>) -> Router {
// See: https://stackoverflow.com/questions/6845772/should-i-use-singular-or-plural-name-convention-for-rest-resources

let v1_api_routes = Router::new()
.route("/", get(about_page_handler).with_state(app_data.clone()))
.route("/", get(redirect_to_about))
.nest("/user", user::routes::router(app_data.clone()))
.nest("/about", about::routes::router(app_data.clone()))
.nest("/category", category::routes::router(app_data.clone()))
Expand All @@ -35,7 +35,7 @@ pub fn router(app_data: Arc<AppData>) -> Router {
.nest("/proxy", proxy::routes::router(app_data.clone()));

let router = Router::new()
.route("/", get(about_page_handler).with_state(app_data.clone()))
.route("/", get(redirect_to_about))
.route("/health_check", get(health_check_handler).with_state(app_data))
.nest(&format!("/{API_VERSION_URL_PREFIX}"), v1_api_routes);

Expand All @@ -52,3 +52,7 @@ pub fn router(app_data: Arc<AppData>) -> Router {
async fn health_check_handler() -> Json<Value> {
Json(json!({ "status": "Ok" }))
}

async fn redirect_to_about() -> Redirect {
Redirect::permanent(&format!("/{API_VERSION_URL_PREFIX}/about"))
}
Loading