it builds! axum and leptos separate routes
This commit is contained in:
parent
bf03d7a180
commit
b8ae6fcb67
4 changed files with 16 additions and 19 deletions
|
@ -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 }
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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::{
|
||||
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};
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue