diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 924d5fa..3a33059 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,6 +3,8 @@ name: Rust on: push: branches: [ "main" ] + pull_request: + branches: [ "main" ] env: CARGO_TERM_COLOR: always @@ -12,17 +14,22 @@ jobs: runs-on: ubuntu-latest + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose deploy: - if: startsWith(github.ref, 'refs/tags/v') + # if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: shuttle-hq/deploy-action@main with: deploy-key: ${{ secrets.SHUTTLE_API_KEY }} + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} diff --git a/.gitignore b/.gitignore index a9be750..09d1f59 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ test.db .DS_Store Secrets.toml +.env diff --git a/Cargo.lock b/Cargo.lock index fc7b848..d608cdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -956,6 +956,7 @@ dependencies = [ "shuttle-runtime", "strum 0.25.0", "strum_macros 0.25.3", + "tokio", "uuid", ] diff --git a/Cargo.toml b/Cargo.toml index f2b2f1b..9e5fb4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,6 @@ env_logger = "0.10" log = "0.4" strum_macros = "0.25.3" strum = { version = "0.25.0", features = ["derive"]} -shuttle-actix-web = "0.35.1" -shuttle-runtime = "0.35.1" +shuttle-actix-web = "0.35.2" +shuttle-runtime = "0.35.2" +tokio = "1.35.1" diff --git a/src/main.rs b/src/main.rs index b4b3d4b..8c87eea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,51 +1,40 @@ -use actix_web::{middleware::Logger, web::{self}, App, HttpServer}; +use actix_web::{ + web::ServiceConfig, + web::{self}, +}; +use shuttle_actix_web::ShuttleActixWeb; pub mod app; pub mod schema; -use app::api::home::{ - all_homes, - add_home, - find_home, - delete_home -}; - -use app::api::room::{add_room, get_room}; +use app::api::home::{add_home, all_homes, delete_home, find_home}; use app::api::item::{add_item, get_items}; +use app::api::room::{add_room, get_room}; -use app::db::{ - initialize_db_pool, - initial_migration -}; +use app::db::{initial_migration, initialize_db_pool}; -// #[cfg(debug_assertions)] -#[actix_web::main] -async fn main() -> std::io::Result<()> { +#[shuttle_runtime::main] +async fn main() -> ShuttleActixWeb { dotenvy::dotenv().ok(); - std::env::set_var("RUST_LOG", "debug"); - std::env::set_var("RUST_BACKTRACE", "1"); - env_logger::init(); let pool = initialize_db_pool(); - log::info!("starting HTTP server at http://localhost:8080"); initial_migration(); - HttpServer::new(move || { - let logger = Logger::default(); - App::new() - .app_data(web::Data::new(pool.clone())) - .wrap(logger) - .service(all_homes) - .service(add_home) - .service(find_home) - .service(delete_home) - .service(add_room) - .service(get_room) - .service(get_items) - .service(add_item) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await + let config = move |cfg: &mut ServiceConfig| { + cfg.app_data(web::Data::new(pool.clone())); + // Homes + cfg.service(all_homes); + cfg.service(add_home); + cfg.service(find_home); + cfg.service(delete_home); + // Rooms + cfg.service(add_room); + cfg.service(get_room); + // Items + cfg.service(add_item); + cfg.service(get_items); + }; + + Ok(config.into()) }