Skip to content

Commit

Permalink
cors tmp enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jul 3, 2024
1 parent 48902c3 commit 06b5a38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
7 changes: 6 additions & 1 deletion crates/delegator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,6 +84,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(),
Expand Down
14 changes: 11 additions & 3 deletions dashboard/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -121,15 +122,19 @@ 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)
}
}
};

reader.readAsArrayBuffer(file);
};

const [isProcessing, setIsProcessing] = useState<number | null>(null);

const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop: ondrop,
});
Expand All @@ -147,13 +152,16 @@ export default function Home() {
{...getRootProps()}
>
<input className="w-full" {...getInputProps()} />
{isDragActive ? (
{isProcessing != null ? (
<p className="text-center">Processing job hash: {isProcessing}</p>
) : isDragActive ? (
<p className="text-center">Drop the Trace here ...</p>
) : (
<p className="text-center">
Drag Trace here, or click to select files
</p>
)}
)
}
</div>
<LinearProgress sx={{ backgroundColor: "transparent" }} />
<Stepper
Expand Down

0 comments on commit 06b5a38

Please sign in to comment.