From cc75823054b9aa1059d6b3e3e88347fb6d5fad93 Mon Sep 17 00:00:00 2001 From: piny4man Date: Sun, 7 Jul 2024 13:32:39 +0200 Subject: [PATCH 1/5] feat: remove shuttle dependency --- api/Cargo.toml | 15 +++++++++++++++ api/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 api/Cargo.toml create mode 100644 api/src/main.rs diff --git a/api/Cargo.toml b/api/Cargo.toml new file mode 100644 index 0000000..a3e4038 --- /dev/null +++ b/api/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "api" +version = "0.2.0" +edition = "2021" +publish = false + +[dependencies] +actix-web = "4.8" +tokio = "1.26.0" +actix-files = "0.6" +shared = { path = "../shared" } +serde = { workspace = true } +serde_json = { workspace = true } +tracing = "0.1.40" +mime = "0.3.17" diff --git a/api/src/main.rs b/api/src/main.rs new file mode 100644 index 0000000..b10350b --- /dev/null +++ b/api/src/main.rs @@ -0,0 +1,33 @@ +use actix_files::Files; +use actix_web::{ + web::{self, scope, Json}, + App, HttpServer, Result, +}; + +use shared::helpers::calculations::calculate_score; +use shared::models::{CompetitorInfo, Score}; + +async fn hello_world() -> &'static str { + "Hello World!" +} + +async fn calculate_results(competitor_info: Json) -> Result> { + let results = calculate_score(competitor_info.into_inner()); + Ok(Json(results)) +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + HttpServer::new(|| { + App::new() + .service( + scope("/api") + .route("hello", web::get().to(hello_world)) + .route("score", web::post().to(calculate_results)), + ) + .service(Files::new("/", "../static").index_file("index.html")) + }) + .bind("127.0.0.1:8080")? + .run() + .await +} From c9b66da1bc846ea5e0b859544d06a783d76ac2bf Mon Sep 17 00:00:00 2001 From: piny4man Date: Sun, 7 Jul 2024 13:37:02 +0200 Subject: [PATCH 2/5] feat: move workspace api --- Cargo.toml | 25 +++++++++---------------- Makefile.toml | 5 ++--- front/Cargo.toml | 2 +- shared/Cargo.toml | 4 ++-- src/main.rs | 35 ----------------------------------- 5 files changed, 14 insertions(+), 57 deletions(-) delete mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 6f47a6f..7549c66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,14 @@ -[package] +[workspace] +members = ["front", "shared", "api"] + +resolver = "2" + +[workspace.package] name = "power-scouter" version = "0.2.0" edition = "2021" publish = false -[workspace] -members = ["front", "shared", "."] - -[dependencies] -shuttle-runtime = "0.39.0" -actix-web = "4.3.1" -shuttle-actix-web = "0.39.0" -tokio = "1.26.0" -actix-files = "0.6.2" -serde = "1.0.152" -serde_json = "1.0.94" -tracing = "0.1.40" -shared = { path = "./shared" } -actix-cors = "0.7.0" -mime = "0.3.17" +[workspace.dependencies] +serde = { version = "1.0", features = ['derive'] } +serde_json = "1.0" diff --git a/Makefile.toml b/Makefile.toml index 8d2c811..1845eaa 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,9 +1,8 @@ -[tasks.shuttle] +[tasks.dev] workspace = false env = { "RUST_LOG" = "trace" } -install_crate = "cargo-shuttle" command = "cargo" -args = ["shuttle", "run"] +args = ["run"] [tasks.serve] workspace = false diff --git a/front/Cargo.toml b/front/Cargo.toml index 711c83d..60fe48e 100644 --- a/front/Cargo.toml +++ b/front/Cargo.toml @@ -16,5 +16,5 @@ panic = "abort" dioxus = "0.4.3" dioxus-web = "0.4.3" log = "0.4.17" -reqwest = { version = "0.11", features = ["json"] } +reqwest = { version = "0.12.5", features = ["json"] } shared = { path = "../shared" } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 1f0e416..cdbb970 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = "1.0.152" -serde_json = "1.0.94" +serde = { workspace = true } +serde_json = { workspace = true } diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index f4ca705..0000000 --- a/src/main.rs +++ /dev/null @@ -1,35 +0,0 @@ -use actix_cors::Cors; -use actix_files::Files; -use actix_web::{ - web::{self, scope, Json, ServiceConfig}, - Result, -}; -use shuttle_actix_web::ShuttleActixWeb; - -use shared::helpers::calculations::calculate_score; -use shared::models::{CompetitorInfo, Score}; - -async fn hello_world() -> &'static str { - "Hello World!" -} - -async fn calculate_results(competitor_info: Json) -> Result> { - let results = calculate_score(competitor_info.into_inner()); - Ok(Json(results)) -} - -#[shuttle_runtime::main] -async fn actix_web( -) -> ShuttleActixWeb { - let config = move |cfg: &mut ServiceConfig| { - let cors = Cors::permissive(); - cfg.service( - scope("/api") - .wrap(cors) - .route("hello", web::get().to(hello_world)) - .route("score", web::post().to(calculate_results)), - ) - .service(Files::new("/", "static").index_file("index.html")); - }; - Ok(config.into()) -} From 9223246f8fc8dbbb1bb1d3ecf62bf6ba1064269a Mon Sep 17 00:00:00 2001 From: piny4man Date: Sun, 7 Jul 2024 18:26:32 +0200 Subject: [PATCH 3/5] chore: remove vscode settings --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 5096bcc..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rust-analyzer.linkedProjects": [ - "./front/Cargo.toml", - "./Cargo.toml", - ] -} \ No newline at end of file From 08f36a2ef790ed54fa3c01dd97143b4cfe6e2667 Mon Sep 17 00:00:00 2001 From: piny4man Date: Sun, 7 Jul 2024 18:26:59 +0200 Subject: [PATCH 4/5] chore: ignore vscode folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 46d56db..bd5db42 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /Cargo.lock /front/dist .env +.vscode From c2994a818f5036de9ecf13a139ab2f6424ecbc4b Mon Sep 17 00:00:00 2001 From: piny4man Date: Sun, 7 Jul 2024 18:55:41 +0200 Subject: [PATCH 5/5] fix: api dev make action --- Makefile.toml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 1845eaa..655f2d9 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,8 +1,10 @@ [tasks.dev] workspace = false -env = { "RUST_LOG" = "trace" } -command = "cargo" -args = ["run"] +script_runner = "@shell" +script = ''' +cd api +cargo run +''' [tasks.serve] workspace = false