I'm using axum for my backend as I want the base url to be configurable so my desktop builds use an external backend. It works fine on desktop and my config is like below:
// Create API routes (unchanged)
let api_routes = Router::new()
.route("/user/{id}", get(api_get_user))
.route("/signin", post(api_try_signin))
.route("/verify-otp", post(api_verify_otp))
.route("/signup", post(api_try_signup));
// Add CORS layer to allow cross-origin requests (adjust as needed)
let cors = CorsLayer::new()
.allow_origin(Any) // Permits all origins (restrict to specific domains for security)
.allow_methods(Any)
.allow_headers(Any);
let router = axum::Router::new()
.nest("/api", api_routes)
.layer(cors) // Apply CORS before Dioxus app
.serve_dioxus_application(ServeConfig::new().unwrap(), App);
let router = router.into_make_service();
This works fine on desktop. I can retrieve data from routes with the utils in this snippet: