Skip to content

Route definitions #4

@jredding97

Description

@jredding97

So I recognize that I've done borderline nothing for this project, but I strongly disagree with how the routes are defined in main.rs and I don't know if that's a coding or library thing.

In my opinion, we should have a function that returns an App with all the routing completed. Then main would just call that function, attach a DB, create an HttpServer around it, and run it.

    let hq_core = HQCore::new();
    // Attach DB controller to core
    hq_core.data(establish_connection());
    // Create the actual HttpServer for core
    let hq_core_http = HttpServer::new(hq_core)
    // Run the server 
    hq_core_http.bind("0.0.0.0:8080").unwrap().run();

And then we'd have a separate file that's something like

    impl HQCore {
        fn new() -> App {
            let app = App::new()
            app.service(
                web::resource("/devices")
                    .route(web::get().to(handlers::devices::list_devices)) // Gets a list of devices
                    .route(web::post().to(handlers::devices::add_device)) // Adds a device
            )
            app.service( ... )
            ....
        }
    }

Obviously not perfect, but I think that will make everything significantly tidier, and easier to modify later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions