From 54894f9de9bad4fecb2a116d59a03cdd003f84c0 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 12 Dec 2024 08:28:04 +0000 Subject: Moves rust workspace to root --- rust/schist_backend/src/main.rs | 48 ----------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 rust/schist_backend/src/main.rs (limited to 'rust/schist_backend/src/main.rs') diff --git a/rust/schist_backend/src/main.rs b/rust/schist_backend/src/main.rs deleted file mode 100644 index 8395681..0000000 --- a/rust/schist_backend/src/main.rs +++ /dev/null @@ -1,48 +0,0 @@ -use schist_schema::migrations::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 { - 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::category::get_all_categories, - ], - ) -} -- cgit v1.2.3