saleor-apps-rs/sitemap-generator/src/routes/mod.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2024-02-27 16:50:48 +00:00
use axum::{
handler::HandlerWithoutStateExt,
http::StatusCode,
2024-03-06 15:42:04 +00:00
routing::{any, get, post},
2024-02-27 16:50:48 +00:00
Router,
};
use tower_http::services::ServeDir;
use crate::app::AppState;
pub mod manifest;
pub mod register;
2024-03-06 15:42:04 +00:00
pub mod webhooks;
2024-02-27 16:50:48 +00:00
use manifest::manifest;
use register::register;
2024-03-06 15:42:04 +00:00
use webhooks::webhooks;
2024-02-27 16:50:48 +00:00
2024-03-06 15:42:04 +00:00
pub fn create_routes(state: AppState) -> Router {
2024-02-27 16:50:48 +00:00
async fn handle_404() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Not found")
}
let service = handle_404.into_service();
2024-03-06 15:42:04 +00:00
//TODO : Fix this relative path issue in workspaces
let serve_dir = ServeDir::new("./sitemap-generator/public").not_found_service(service);
2024-02-27 16:50:48 +00:00
Router::new()
//handles just path, eg. localhost:3000/
.route(
"/",
get(|| async { "Your app got installed successfully!" }),
)
//handles files, eg. localhost:3000/logo.png
.fallback_service(serve_dir)
.route("/api/manifest", get(manifest))
.route("/api/register", post(register))
2024-03-06 15:42:04 +00:00
.route("/api/webhooks", any(webhooks))
2024-02-27 16:50:48 +00:00
.with_state(state)
}