Skip to content
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
2 changes: 1 addition & 1 deletion cot/src/openapi/swagger_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl App for SwaggerUi {
Ok::<_, crate::Error>(Html::new(swagger))
};

let mut urls = vec![Route::with_handler("/", swagger_handler)];
let mut urls = vec![Route::with_handler_and_name("/", swagger_handler, "index")];
if self.serve_openapi {
urls.push(Route::with_handler("/openapi.json", openapi_json));
}
Expand Down
15 changes: 11 additions & 4 deletions examples/json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use cot::error::handler::{DynErrorPageHandler, RequestError};
use cot::json::Json;
use cot::openapi::swagger_ui::SwaggerUi;
use cot::project::{MiddlewareContext, RegisterAppsContext, RootHandler, RootHandlerBuilder};
use cot::response::IntoResponse;
use cot::response::{IntoResponse, Response};
use cot::router::method::openapi::api_post;
use cot::router::{Route, Router};
use cot::router::{Route, Router, Urls};
use cot::static_files::StaticFilesMiddleware;
use cot::{App, AppBuilder, Project};
use cot::{App, AppBuilder, Project, reverse_redirect};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, schemars::JsonSchema)]
Expand All @@ -30,6 +30,10 @@ async fn add(Json(add_request): Json<AddRequest>) -> Json<AddResponse> {
Json(response)
}

async fn index(urls: Urls) -> cot::Result<Response> {
Ok(reverse_redirect!(urls, "swagger-ui:index")?)
}

struct AddApp;

impl App for AddApp {
Expand All @@ -38,7 +42,10 @@ impl App for AddApp {
}

fn router(&self) -> Router {
Router::with_urls([Route::with_api_handler("/add/", api_post(add))])
Router::with_urls([
Route::with_api_handler_and_name("/add/", api_post(add), "add"),
Route::with_handler_and_name("/", index, "index"),
])
}
}

Expand Down
Loading