Skip to content

Commit

Permalink
it builds! axum and leptos separate routes
Browse files Browse the repository at this point in the history
  • Loading branch information
djkato committed Jun 17, 2024
1 parent bf03d7a commit b8ae6fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app-template-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT OR Apache-2.0"
crate-type = ["cdylib", "rlib"]

[dependencies]
axum = { workspace = true, optional = true }
axum = { workspace = true, optional = true, features = ["macros"] }
console_error_panic_hook = { workspace = true }
leptos = { workspace = true, features = ["nightly"] }
anyhow = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion app-template-ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn App() -> impl IntoView {
}

#[cfg(feature = "ssr")]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, axum::extract::FromRef)]
pub struct AppState {
pub saleor_app: std::sync::Arc<tokio::sync::Mutex<saleor_app_sdk::SaleorApp>>,
pub config: saleor_app_sdk::config::Config,
Expand Down
29 changes: 13 additions & 16 deletions app-template-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ mod error_template;
async fn main() -> Result<(), std::io::Error> {

use std::sync::Arc;
use axum::{middleware, routing::{post,get}, Router};
use axum::{middleware, routing::{get, post}, Router};
use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use leptos_axum::{generate_route_list, LeptosRoutes };
use app::*;
use fileserv::file_and_error_handler;
use saleor_app_sdk::middleware::verify_webhook_signature::webhook_signature_verifier;
use tokio::sync::Mutex;
use saleor_app_sdk::{
cargo_info,
config::Config,
manifest::{AppManifestBuilder, AppPermission},
webhooks::{AsyncWebhookEventType, WebhookManifestBuilder},
SaleorApp,
};
use saleor_app_sdk::{
cargo_info,
config::Config,
manifest::{AppManifestBuilder, AppPermission},
webhooks::{AsyncWebhookEventType, WebhookManifestBuilder},
SaleorApp,
};

use crate::routes::api::{manifest::manifest, register::register, webhooks::webhooks};

Expand Down Expand Up @@ -103,16 +103,13 @@ use saleor_app_sdk::{
let state_1 = app_state.clone();
let app =
Router::new()
.layer(middleware::from_fn(webhook_signature_verifier))
.route("/api/webhooks", post(webhooks))
.route("/api/register", post(register))
.route("/api/manifest", get(manifest))
// .leptos_routes_with_context(&leptos_options, routes,move || provide_context(state_1.clone()) , App)
.leptos_routes(&leptos_options, routes, App)
.leptos_routes_with_context(&app_state, routes,move || provide_context(state_1.clone()) , App)
.fallback(file_and_error_handler)
.route("/api/webhooks", post(webhooks).route_layer(middleware::from_fn(webhook_signature_verifier)))
.route("/api/register", post(register).route_layer(middleware::from_fn(webhook_signature_verifier)))
.route("/api/manifest", get(manifest))
.with_state(app_state.clone());


let listener = tokio::net::TcpListener::bind(
"0.0.0.0:".to_owned()
+ config
Expand Down
2 changes: 1 addition & 1 deletion app-template-ui/src/routes/api/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use saleor_app_sdk::manifest::AppManifest;

use crate::{app::AppState, error_template::AxumError};

pub fn manifest(State(state): State<AppState>) -> Result<Json<AppManifest>, AxumError> {
pub async fn manifest(State(state): State<AppState>) -> Result<Json<AppManifest>, AxumError> {
Ok(Json(state.manifest))
}

0 comments on commit b8ae6fc

Please sign in to comment.