drogonframework / drogonframework/drogon

Controller auto-registration not working for HttpController

Open
#2,391 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 13h
Merged PRs (30d)
14

Description

### Description

I'm experiencing an issue where a controller inheriting from `HttpController` 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:

```cpp
class MetricsController : public drogon::HttpController
{
public:
METHOD_LIST_BEGIN
METHOD_ADD(MetricsController::getMetrics, "/metrics", Get);
METHOD_LIST_END

void getMetrics(const HttpRequestPtr &req,
std::function &&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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.