0

I am using Axum to serve a React frontend which makes api calls to the same Axum server for it's backend. However, sometimes the server returns 404 errors for only some of my API routes. When I load the frontend, some of the routes say "404" in my browser console. I've noticed, I seem to get these errors only when on public wifi. Although, it seems very strange that the Axum server still allows me to access the frontend... since it's all coming from the same HTTP server? Why would some routes show 404?

let client_routes = Router::new()
    .route("/", get(|| async { "Hello, World!" }))
    .route("/getinfo", post(client::getinfo));

let panel_routes = Router::new()
    .route("/clientlist", get(panel::clientlist))
    .route("/onlineusers", get(panel::get_online_users))


let api_routes = Router::new()
    .nest("/control", client_routes)
    .nest("/panel", panel_routes)
    .with_state(db_pool);

let frontend_service = ServeDir::new("./html");
let cors = CorsLayer::new().allow_origin(Any).allow_methods(Any).allow_headers(Any);
let app = Router::new().layer(cors).nest_service("/api", api_routes).nest_service("/panel", frontend_service);
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
    .serve(app.into_make_service_with_connect_info::<SocketAddr>())
    .await
    .unwrap();

Here is the code I am using to run the Axum server. I've tried accessing the frontend via. 127.0.0.1:3000/panel and localhost:3000/panel.

Sometimes, 127.0.0.1 works, but other times it doesn't and localhost works better. Is this some sort of firewall on the wifi or is there a error in the way my HTTP server is running?

0 Answers0