it builds! axum and leptos separate routes

This commit is contained in:
Djkáťo 2024-06-17 23:51:41 +02:00
parent bf03d7a180
commit b8ae6fcb67
4 changed files with 16 additions and 19 deletions

View file

@ -15,7 +15,7 @@ license = "MIT OR Apache-2.0"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
axum = { workspace = true, optional = true } axum = { workspace = true, optional = true, features = ["macros"] }
console_error_panic_hook = { workspace = true } console_error_panic_hook = { workspace = true }
leptos = { workspace = true, features = ["nightly"] } leptos = { workspace = true, features = ["nightly"] }
anyhow = { workspace = true, optional = true } anyhow = { workspace = true, optional = true }

View file

@ -36,7 +36,7 @@ pub fn App() -> impl IntoView {
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
#[derive(Debug, Clone)] #[derive(Debug, Clone, axum::extract::FromRef)]
pub struct AppState { pub struct AppState {
pub saleor_app: std::sync::Arc<tokio::sync::Mutex<saleor_app_sdk::SaleorApp>>, pub saleor_app: std::sync::Arc<tokio::sync::Mutex<saleor_app_sdk::SaleorApp>>,
pub config: saleor_app_sdk::config::Config, pub config: saleor_app_sdk::config::Config,

View file

@ -21,7 +21,7 @@ mod error_template;
async fn main() -> Result<(), std::io::Error> { async fn main() -> Result<(), std::io::Error> {
use std::sync::Arc; use std::sync::Arc;
use axum::{middleware, routing::{post,get}, Router}; use axum::{middleware, routing::{get, post}, Router};
use leptos::*; use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes }; use leptos_axum::{generate_route_list, LeptosRoutes };
use app::*; use app::*;
@ -103,16 +103,13 @@ use saleor_app_sdk::{
let state_1 = app_state.clone(); let state_1 = app_state.clone();
let app = let app =
Router::new() Router::new()
.layer(middleware::from_fn(webhook_signature_verifier)) .leptos_routes_with_context(&app_state, routes,move || provide_context(state_1.clone()) , App)
.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)
.fallback(file_and_error_handler) .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()); .with_state(app_state.clone());
let listener = tokio::net::TcpListener::bind( let listener = tokio::net::TcpListener::bind(
"0.0.0.0:".to_owned() "0.0.0.0:".to_owned()
+ config + config

View file

@ -3,6 +3,6 @@ use saleor_app_sdk::manifest::AppManifest;
use crate::{app::AppState, error_template::AxumError}; 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)) Ok(Json(state.manifest))
} }