Skip to content

Controller auto-registration not working for HttpController #2391

@then0de

Description

@then0de

Description

I'm experiencing an issue where a controller inheriting from HttpController<MyController> is not being auto-registered, even though the structure follows Drogon's documented conventions.

Steps to Reproduce

  1. Create a controller class in the global namespace:
class MetricsController : public drogon::HttpController<MetricsController>
{
public:
    METHOD_LIST_BEGIN
        METHOD_ADD(MetricsController::getMetrics, "/metrics", Get);
    METHOD_LIST_END

    void getMetrics(const HttpRequestPtr &req,
                    std::function<void(const HttpResponsePtr &)> &&callback);
};

2. Implement the method in MetricsController.cc and include it in CMakeLists.txt.

3. Build and run the project. The server starts, but /metrics returns a 404.

What I Expected
The /metrics route should be automatically registered and respond with the controller logic.

What Happened Instead
The route returns a 404. No logs from the controller appear, and the method is never called.

Environment
Drogon version: 1.9.11

OS: Kubuntu (Ubuntu 25.04)

C++ standard: C++23

Build system: CMake

Additional Notes
Manual registration using registerHandler() works fine.

The controller is in the global namespace and compiled into the binary.

No custom namespaces or filters are used.

Any guidance or clarification would be appreciated. If this is a bug, I’d be happy to help isolate it further or submit a PR.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions