]> git.seodisparate.com - EN605.607.81.SP22_ASDM_Project/commitdiff
Impl being able to debug locally debug_local_testing
authorStephen Seo <seo.disparate@gmail.com>
Tue, 20 Sep 2022 10:26:50 +0000 (19:26 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 18 Dec 2024 03:54:15 +0000 (12:54 +0900)
CORS (Cross-Origin Resource Sharing) prevented the application's
networked (multiplayer) support from working locally. The
debug_local_testing branch has changes to allow running the game
locally. The backend must be run with `cargo run --release` or `cargo
run`, and the frontend must be run with `trunk serve`, and the
browser(s) must open `http://localhost:8080/`.

back_end/src/main.rs
front_end/src/constants.rs

index e34b272c26d30fc9a9ad1141a8ed7bea64c168e7..55702c6f7557747d5e4cbc364766634f55fdf3b0 100644 (file)
@@ -45,8 +45,9 @@ async fn main() {
 
     start_db_handler_thread(db_rx, SQLITE_DB_PATH.into(), s_helper_tx.clone());
 
-    let route = warp::body::content_length_limit(1024 * 32)
-        .and(warp::body::bytes())
+    let route = //warp::body::content_length_limit(1024 * 32)
+        //.and(warp::body::bytes())
+        warp::body::bytes()
         .and_then(move |bytes: bytes::Bytes| {
             let db_tx_clone = db_tx_clone.clone();
             let s_helper_tx_clone = s_helper_tx.clone();
@@ -55,24 +56,48 @@ async fn main() {
                 if let Ok(body_str) = body_str_result {
                     let json_result = serde_json::from_str(body_str);
                     if let Ok(json_value) = json_result {
-                        Ok(warp::reply::with_header(
+                        let reply = warp::reply::with_header(
                             json_handlers::handle_json(json_value, db_tx_clone, s_helper_tx_clone)
                                 .unwrap_or_else(|e| e),
                             "Content-Type",
                             "application/json",
+                        );
+                        let reply = warp::reply::with_header(
+                            reply,
+                            "Access-Control-Allow-Headers",
+                            "*",
+                        );
+                        Ok::<Box<dyn warp::reply::Reply>, Rejection>(Box::new(
+                            warp::reply::with_header(reply, "Access-Control-Allow-Origin", "*"),
                         ))
                     } else {
-                        Ok(warp::reply::with_header(
+                        let reply = warp::reply::with_header(
                             String::from("{\"type\": \"invalid_syntax\"}"),
                             "Content-Type",
                             "application/json",
+                        );
+                        let reply = warp::reply::with_header(
+                            reply,
+                            "Access-Control-Allow-Headers",
+                            "*",
+                        );
+                        Ok::<Box<dyn warp::reply::Reply>, Rejection>(Box::new(
+                            warp::reply::with_header(reply, "Access-Control-Allow-Origin", "*"),
                         ))
                     }
                 } else {
-                    Ok::<warp::reply::WithHeader<String>, Rejection>(warp::reply::with_header(
+                    let reply = warp::reply::with_header(
                         String::from("{\"type\": \"invalid_syntax\"}"),
                         "Content-Type",
                         "application/json",
+                    );
+                    let reply = warp::reply::with_header(
+                        reply,
+                        "Access-Control-Allow-Headers",
+                        "*",
+                    );
+                    Ok::<Box<dyn warp::reply::Reply>, Rejection>(Box::new(
+                        warp::reply::with_header(reply, "Access-Control-Allow-Origin", "*"),
                     ))
                 }
             }
index b693223e3888121e14634dac6a0b46b828e9e8be..89281e4169a201dec4735cbd207f6f00d284d3df 100644 (file)
@@ -37,7 +37,7 @@ pub const BACKEND_PHRASE_MAX_LENGTH: usize = 128;
 // TODO: Change this to "https://asdm.seodisparate.com/api" when backend is installed
 #[allow(dead_code)]
 #[cfg(debug_assertions)]
-pub const BACKEND_URL: &str = "http://testlocalhost/api";
+pub const BACKEND_URL: &str = "http://localhost:1237/";
 
 #[allow(dead_code)]
 #[cfg(not(debug_assertions))]