Refactor server and API handler for improved error handling and routing logic. Updated request handling to use Incoming type and added HTTP/1.1 restriction. Enhanced splash screen logic in the frontend to manage routing based on onboarding and setup states. Fixed WebSocket client initialization to ensure lazy loading and error handling. Cleaned up unused imports and variables across multiple files.

This commit is contained in:
zazawowow
2026-01-24 23:09:46 +00:00
parent 731cd67cfb
commit c293bd9880
37 changed files with 426 additions and 30 deletions

View File

@@ -3,6 +3,7 @@ use crate::config::Config;
use anyhow::Result;
use http_body_util::{BodyExt, Full};
use hyper::body::Bytes;
use hyper::body::Incoming;
use hyper::{Method, Request, Response, StatusCode};
use hyper_util::rt::TokioIo;
use std::sync::Arc;
@@ -26,15 +27,16 @@ impl ApiHandler {
pub async fn handle_request(
&self,
req: Request<http_body_util::Body<Bytes>>,
req: Request<Incoming>,
) -> Result<Response<Full<Bytes>>> {
let path = req.uri().path();
let method = req.method();
// Convert Incoming body to bytes
// Convert body to bytes
let (parts, body) = req.into_parts();
let collected = body.collect().await
.map_err(|e| anyhow::anyhow!("Failed to read body: {}", e))?;
use http_body_util::BodyExt;
let collected: http_body_util::Collected<Bytes> = body.collect().await
.map_err(|_e| anyhow::anyhow!("Failed to read body"))?;
let body_bytes = collected.to_bytes();
// Reconstruct request with Full<Bytes> body for RPC handler
@@ -43,11 +45,11 @@ impl ApiHandler {
debug!("{} {}", method, path);
// Route requests
match (method, path) {
(&Method::POST, "/rpc/v1") => {
match (method, path.as_str()) {
(Method::POST, "/rpc/v1") => {
self.rpc_handler.handle(req_with_bytes).await
}
(&Method::GET, "/health") => {
(Method::GET, "/health") => {
Ok(Response::builder()
.status(StatusCode::OK)
.body(Full::new(Bytes::from("OK")))