Skip to content

Commit

Permalink
feat/docs: set root path and print errors
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Aug 24, 2024
1 parent 3ba4c0f commit ed738cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A simple [axum](https://github.com/tokio-rs/axum) API for compiling TeX/LaTeX wi
Simply cURL the endpoint like in the following.

```bash
curl -O 'https://winstxnhdw-tectonic-api.hf.space/v1/compile' \
curl -O 'https://winstxnhdw-tectonic-api.hf.space/api/v1/compile' \
-H 'Content-Type: application/json' \
-d \
'{
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ use utoipa::OpenApi;
struct ApiSpecification;

pub fn app() -> Router {
Router::new().route("/", get(())).merge(v1::router()).merge(
utoipa_swagger_ui::SwaggerUi::new("/docs")
.url("/api-docs/openapi.json", ApiSpecification::openapi()),
Router::new().nest(
"/api",
Router::new().route("/", get(())).merge(v1::router()).merge(
utoipa_swagger_ui::SwaggerUi::new("/docs")
.url("/api-docs/openapi.json", ApiSpecification::openapi()),
),
)
}
14 changes: 9 additions & 5 deletions src/v1/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ pub async fn compile(Json(payload): Json<CompileSchema>) -> impl IntoResponse {
.header(CONTENT_DISPOSITION, "attachment; filename=\"compiled.pdf\"")
.body(Body::from(pdf))
.unwrap(),
_ => Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(CONTENT_TYPE, "text/plain")
.body(Body::from("Failed to compile to PDF!"))
.unwrap(),
Err(error) => {
eprintln!("{:?}", error);

Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(CONTENT_TYPE, "text/plain")
.body(Body::from("Failed to compile to PDF!"))
.unwrap()
}
}
}

0 comments on commit ed738cf

Please sign in to comment.