(
axum::extract::Path(path): axum::extract::Path<String>,
)
| 39 | .route("/api/sponsor", post(sponsor_api::create_checkout)) |
| 40 | .route("/api/sponsor/portal", get(sponsor_api::portal_redirect)) |
| 41 | .route("/og/{*path}", get(og_image)) |
| 42 | .leptos_routes(&leptos_options, routes, App) |
| 43 | .fallback_service(ServeDir::new(site_root)) |
| 44 | .layer(Extension(sponsor_api::SponsorState::from_env())) |
| 45 | .with_state(leptos_options); |
| 46 | |
| 47 | let listener = tokio::net::TcpListener::bind(&addr).await?; |
| 48 | tracing::info!("perro_website @ http://{addr}"); |
| 49 | axum::serve(listener, app.into_make_service()).await?; |
| 50 | Ok(()) |
| 51 | } |
| 52 | |
| 53 | #[cfg(feature = "ssr")] |
| 54 | async fn og_image( |
| 55 | axum::extract::Path(path): axum::extract::Path<String>, |
| 56 | ) -> impl axum::response::IntoResponse { |
| 57 | use axum::response::IntoResponse; |
| 58 | |
| 59 | let wants_png = path.ends_with(".png"); |
| 60 | let normalized = path |
| 61 | .strip_suffix(".png") |
| 62 | .or_else(|| path.strip_suffix(".svg")) |
| 63 | .unwrap_or(&path); |
| 64 | let (title, label, summary) = og_text(normalized); |
| 65 | let svg = social_svg(&title, &label, &summary); |
| 66 | if wants_png { |
| 67 | return match svg_to_png(&svg) { |
| 68 | Ok(png) => ([(axum::http::header::CONTENT_TYPE, "image/png")], png).into_response(), |
| 69 | Err(_) => ( |
| 70 | axum::http::StatusCode::INTERNAL_SERVER_ERROR, |
| 71 | "social image render failed", |
| 72 | ) |
| 73 | .into_response(), |
| 74 | }; |
| 75 | } |
nothing calls this directly
no test coverage detected