diff options
| author | Joe Carstairs <me@joeac.net> | 2024-10-16 12:51:21 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-10-16 12:51:21 +0100 |
| commit | 27b95c9186bd45edd4c982a7cc89cf69cf2c5d46 (patch) | |
| tree | bf104ff9d64e601bfec5516eb51ef298f3095e9b /backend/src/main.rs | |
| parent | 76974785294089965efc3f55b2a08d4089029c52 (diff) | |
All backend stuff lives in backend folder
Diffstat (limited to 'backend/src/main.rs')
| -rw-r--r-- | backend/src/main.rs | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/backend/src/main.rs b/backend/src/main.rs deleted file mode 100644 index c3e02e5..0000000 --- a/backend/src/main.rs +++ /dev/null @@ -1,57 +0,0 @@ -use diesel::SqliteConnection; -use diesel_migrations::MigrationHarness; -use diesel_migrations::{embed_migrations, EmbeddedMigrations}; -use rocket::fairing::AdHoc; -use rocket::http::ContentType; -use rocket::{launch, routes, Build, Rocket}; - -use crate::databases::UserDataDb; - -pub mod databases; -pub mod models; -pub mod queries; -pub mod routes; -pub mod schema; -pub mod utils; - -pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); - -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, - ], - ) -} |
