diff options
Diffstat (limited to 'rust/app/src/main.rs')
| -rw-r--r-- | rust/app/src/main.rs | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/rust/app/src/main.rs b/rust/app/src/main.rs deleted file mode 100644 index dca6096..0000000 --- a/rust/app/src/main.rs +++ /dev/null @@ -1,51 +0,0 @@ -use budgeting_app_core::MIGRATIONS; -use diesel::SqliteConnection; -use diesel_migrations::MigrationHarness; -use rocket::fairing::AdHoc; -use rocket::http::ContentType; -use rocket::{launch, routes, Build, Rocket}; - -use crate::databases::UserDataDb; - -pub mod databases; -pub mod routes; - -fn run_database_migrations(connection: &mut SqliteConnection) { - connection - .run_pending_migrations(MIGRATIONS) - .expect("Error running database migrations"); -} - -#[launch] -async fn rocket() -> Rocket<Build> { - rocket::build() - .attach(UserDataDb::fairing()) - .attach(AdHoc::on_liftoff("Database Migration", |rocket| { - Box::pin(async move { - let user_data_db = UserDataDb::get_one(rocket).await.expect( - "Failed to get connection to user data database in order to run migrations", - ); - user_data_db.run(run_database_migrations).await; - }) - })) - .attach(AdHoc::on_response("Add CORS headers", |_req, res| { - Box::pin(async move { - res.set_header(ContentType::JSON); - res.set_header(rocket::http::Header::new( - "Access-Control-Allow-Origin", - "http://localhost:5173", - )); - }) - })) - .mount( - "/", - routes![ - routes::account::get_all_accounts, - routes::account::create_account, - routes::balance::get_all_category_balances, - routes::budget::get_current_category_budget_per_category, - routes::budget_update::get_all_budget_updates, - routes::category::get_all_categories, - ], - ) -} |
