Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axum Example not working #2439

Open
martinonicolas opened this issue Dec 5, 2024 · 0 comments
Open

Axum Example not working #2439

martinonicolas opened this issue Dec 5, 2024 · 0 comments

Comments

@martinonicolas
Copy link

[DatabaseConnection] is passed as State .with_state(state) in Axum Server but this don't work. [DatabaseConnection] can't be shared across threads.

In examples/axum_example/api/src/lib.rs

...
#[derive(Clone)]
struct AppState {
    templates: Tera,
    conn: DatabaseConnection,
}
...
dotenvy::dotenv().ok();
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
let conn = Database::connect(db_url)
        .await
        .expect("Database connection failed");
let templates = ...
let state = AppState { templates, conn };
...
let app = Router::new()
        .route("/", get(list_posts).post(create_post))
        ...
        .with_state(state);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant