saleor-apps-rs/saleor-app-template/src/routes/mod.rs

36 lines
1,003 B
Rust
Raw Normal View History

2024-02-27 16:50:48 +00:00
use axum::{
handler::HandlerWithoutStateExt,
http::StatusCode,
routing::{get, post},
Router,
};
use saleor_app_sdk::apl::APL;
use tower_http::services::ServeDir;
use crate::app::AppState;
pub mod manifest;
pub mod register;
use manifest::manifest;
use register::register;
pub fn create_routes<T: APL + 'static>(state: AppState<T>) -> Router {
async fn handle_404() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Not found")
}
let service = handle_404.into_service();
let serve_dir = ServeDir::new("saleor-app-template/public").not_found_service(service);
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))
.with_state(state)
}