diff --git a/Cargo.toml b/Cargo.toml index 00fa4b7..2a28df6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ axum = "0.7.5" hyper = { version = "1.0", features = [] } hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } tower = { version = "0.4", features = ["util"] } -tower-http = { version = "0.5", features = ["timeout", "trace"] } +tower-http = { version = "0.5", features = ["timeout", "trace", "cors"] } zetina-common = { path = "crates/common" } zetina-compiler = { path = "crates/compiler" } diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index 8ae0050..a7a03fb 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -16,7 +16,11 @@ use tokio::{ net::TcpListener, sync::{broadcast, mpsc}, }; -use tower_http::{timeout::TimeoutLayer, trace::TraceLayer}; +use tower_http::{ + cors::{Any, CorsLayer}, + timeout::TimeoutLayer, + trace::TraceLayer, +}; use tracing_subscriber::EnvFilter; use zetina_common::{ graceful_shutdown::shutdown_signal, @@ -80,6 +84,7 @@ async fn main() -> Result<(), Box> { // Graceful shutdown will wait for outstanding requests to complete. Add a timeout so // requests don't hang forever. TimeoutLayer::new(Duration::from_secs(10)), + CorsLayer::new().allow_origin(Any).allow_methods(Any).allow_headers(Any), )) .with_state(ServerState { signing_key: node_account.get_signing_key().to_owned(), diff --git a/dashboard/src/app/page.tsx b/dashboard/src/app/page.tsx index 8bc1b4e..a744256 100644 --- a/dashboard/src/app/page.tsx +++ b/dashboard/src/app/page.tsx @@ -13,6 +13,7 @@ import StepConnector, { stepConnectorClasses, } from "@mui/material/StepConnector"; import { DelegateRequest, DelegateResponse } from "./api"; +import { useState } from "react"; const steps = [ "Job propagated to network", @@ -105,7 +106,7 @@ export default function Home() { }); try { - const response = await fetch("127.0.0.1:3010/delegate", { + const response = await fetch("http://localhost:3010/delegate", { method: "POST", headers: { "Content-Type": "application/json", @@ -121,8 +122,10 @@ export default function Home() { await response.json(), ); console.log("Job hash:", data.job_hash); + setIsProcessing(data.job_hash) } catch (error) { console.error("Failed to upload file:", error); + setIsProcessing(null) } } }; @@ -130,6 +133,8 @@ export default function Home() { reader.readAsArrayBuffer(file); }; + const [isProcessing, setIsProcessing] = useState(null); + const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop: ondrop, }); @@ -147,13 +152,16 @@ export default function Home() { {...getRootProps()} > - {isDragActive ? ( + {isProcessing != null ? ( +

Processing job hash: {isProcessing}

+ ) : isDragActive ? (

Drop the Trace here ...

) : (

Drag Trace here, or click to select files

- )} + ) + }