首次提交

This commit is contained in:
2026-06-16 11:18:22 +08:00
commit 068ef188e7
201 changed files with 57503 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#include <drogon/drogon.h>
using namespace drogon;
class GlobalMid : public HttpMiddleware<GlobalMid, false> {
public:
void invoke(const HttpRequestPtr &req,
MiddlewareNextCallback &&next,
MiddlewareCallback &&done) override {
LOG_DEBUG << "进入全局中间件:" << req->path();
next([done](auto resp) {
resp->addHeader("X-Global", "Yes");
LOG_DEBUG << "离开全局中间件";
done(resp);
});
}
};
int main() {
app().registerMiddleware(std::make_shared<GlobalMid>());
app().registerHandler("/hello", [](const HttpRequestPtr &request,
std::function<void(const HttpResponsePtr &)> &&cb){
auto resp = HttpResponse::newHttpResponse();
resp->setBody("OK");
cb(resp);
}, {Get});
app().addListener("0.0.0.0", 80);
app().run();
}