Actix-web: App data is not configured

I'm using an actix-web server as a visualizer for my simulator. It's been running with actix-web 1.0 for a long time, but I decided to update it to 2.0. Converting the client in the simulator went fine, but I've hit a wall with the server. The code compiles, but no matter what I do, I get

App data is not configured, to configure use App::data()

when I click the one button on the web page.

Here's a small(ish) case that causes the error.

#[actix_rt::main]
async fn main() {
    let index_data = web::Data::new("index.html"); 
    let geo_data = web::Data::new(geometry::AppGeometry::default());
    let hello_data = web::Data::new(hello::AppCells::default());
    HttpServer::new(move || {
        App::new()
            
            .app_data(index_data.clone())
            .app_data(hello_data.clone())
            .app_data(geo_data.clone())

            .route("/",web::get().to(index::index))
            
            .service(replay::post())
        })
        .keep_alive(100usize)
        .bind("127.0.0.1:8088")
        .unwrap()
        .run()
        .await
        .unwrap();
}

replay::post() uses AppGeometry and AppCells, but it isn't small.

I've searched web, and I tried data instead of app_data.

What is your replay::post() signature?

It should use web::Data<geometry::AppGeometry> as argument type.

Sorry, I need to actually look at my code before posting. replay::post() just defines the route. It is replay_from_data() that uses AppGeometry and AppCells.

pub fn post() -> Scope {
    web::scope("/replay")
        .data(web::Data::new(AppCells::default()))
        .route("", web::post().to(replay_from_data))
}

Looking at the code, I see I have a .data() statement. I have no idea why it's there. I probably cribbed it from somewhere when I wrote the version for actix-web 1.0. Removing that statement solved the problem

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.