diff --git a/Dockerfile b/Dockerfile index a9be95b..153fe5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ COPY style ./style COPY public ./public # 1. Build Axum SSR server binary -RUN cargo build --release --locked --bin server +RUN cargo build --release --locked -p server --bin server # 2. Build Leptos WASM hydrate bundle and assemble /src/target/site RUN cargo build --profile wasm-release --locked --target wasm32-unknown-unknown -p frontend \ diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 181e5ad..408d1ad 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -6,7 +6,7 @@ version.workspace = true [lib] crate-type = ["cdylib", "rlib"] -[dependencies] +[target.'cfg(target_arch = "wasm32")'.dependencies] app = { workspace = true, features = ["hydrate"] } leptos = { workspace = true, features = ["hydrate"] } console_error_panic_hook = { workspace = true } diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs index c91f67f..64cfecb 100644 --- a/frontend/src/lib.rs +++ b/frontend/src/lib.rs @@ -1,5 +1,4 @@ -#![recursion_limit = "256"] - +#[cfg(target_arch = "wasm32")] #[wasm_bindgen::prelude::wasm_bindgen] pub fn hydrate() { console_error_panic_hook::set_once(); diff --git a/server/src/main.rs b/server/src/main.rs index 7e710e3..1b6f971 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -185,6 +185,77 @@ async fn serve_photo(State(pipeline): State, Path(photo_id): Path = Router::new() + .route("/health/live", get(health_live)) + .with_state(pipeline.clone()) + .leptos_routes_with_context( + &leptos_options, + routes, + move || { + provide_context(pipe_for_ctx.clone()); + }, + { + let opts = leptos_options.clone(); + move || app::shell(opts.clone()) + }, + ) + .fallback(leptos_axum::file_and_error_handler(app::shell)) + .with_state(leptos_options.clone()); + + for uri in ["/", "/?q=test", "/recent", "/place/kakao%3A1", "/nonexistent-404-path"] { + use axum::body::to_bytes; + let pipe = pipeline.clone(); + let opts = leptos_options.clone(); + let handler = leptos_axum::render_app_to_stream_with_context( + move || { + provide_context(pipe.clone()); + }, + move || app::shell(opts.clone()), + ); + let req = Request::builder() + .uri(uri) + .header("Accept", "text/html") + .body(Body::empty()) + .unwrap(); + let resp = handler(req).await; + assert_eq!(resp.status(), StatusCode::OK); + let bytes = to_bytes(resp.into_body(), usize::MAX).await.unwrap(); + assert!(!bytes.is_empty()); + } + } #[test] fn missing_job_returns_a_terminal_error() {