Skip to content

Commit

Permalink
feat: spawn home enpoint from tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
piny4man committed Jul 20, 2024
1 parent e421017 commit 39d8193
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --manifest-path api/Cargo.toml
RUN cargo build --release

FROM debian:bookworm-slim AS runtime
RUN apt update
RUN apt install ca-certificates -y
WORKDIR /app
COPY --from=builder /app/static /usr/local/bin
COPY --from=builder /app/target/release/api /usr/local/bin
COPY public/ /usr/local/bin
COPY --from=builder /app/target/release/power-scouter /usr/local/bin
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/api"]
ENTRYPOINT ["/usr/local/bin/power-scouter"]
39 changes: 22 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod routes;

use axum::{
extract::Json,
response::{self, Html},
response::Html,
routing::{get, post},
Router,
};
Expand All @@ -18,22 +18,6 @@ use helpers::calculations::calculate_score;
use models::{CompetitorInfo, Score};
use routes::home::home_route;

async fn hello_world() -> &'static str {
"Hello World!"
}

async fn calculate_results(Json(competitor_info): Json<CompetitorInfo>) -> Json<Score> {
let results = calculate_score(competitor_info);
Json(results)
}

async fn home_endpoint() -> response::Result<Html<String>> {
let mut app = VirtualDom::new(home_route);
let _ = app.rebuild();

Ok(Html(dioxus_ssr::render(&app)))
}

#[tokio::main]
async fn main() {
let router = Router::new()
Expand All @@ -48,3 +32,24 @@ async fn main() {

axum::serve(listener, router).await.unwrap();
}

async fn hello_world() -> &'static str {
"Hello World!"
}

async fn calculate_results(Json(competitor_info): Json<CompetitorInfo>) -> Json<Score> {
let results = calculate_score(competitor_info);
Json(results)
}

async fn home_endpoint() -> Html<String> {
tokio::task::spawn_blocking(move || async move {
let mut app = VirtualDom::new(home_route);
let _ = app.rebuild();

Html(dioxus_ssr::render(&app))
})
.await
.unwrap()
.await
}

0 comments on commit 39d8193

Please sign in to comment.