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

45 lines
1.4 KiB
Rust
Raw Normal View History

2024-02-27 16:50:48 +00:00
use axum::{
handler::HandlerWithoutStateExt,
http::StatusCode,
middleware,
2024-03-06 15:42:04 +00:00
routing::{any, get, post},
2024-02-27 16:50:48 +00:00
Router,
};
use saleor_app_sdk::middleware::verify_webhook_signature::webhook_signature_verifier;
2024-02-27 16:50:48 +00:00
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
2024-03-12 19:48:20 +00:00
//TODO Query for everything using the app auth token
//TODO "Failed fetching initial products: More than one channel exists, please spocify which
//one"
2024-02-27 16:50:48 +00:00
Router::new()
.route("/api/webhooks", any(webhooks))
.layer(middleware::from_fn(webhook_signature_verifier))
2024-02-27 16:50:48 +00:00
//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))
.with_state(state)
}