Hello. I create controller by command: drogon_ctl create controller PingController:
PingController.h:
#pragma once
#include <drogon/HttpSimpleController.h>
using namespace drogon;
class PingController : public drogon::HttpSimpleController<PingController>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
PATH_ADD("/PING", Get);
PATH_LIST_END
};
PingController.c:
#include "PingController.h"
void PingController::asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback)
{
// write your application logic here
auto resp = HttpResponse::newHttpResponse();
resp->setStatusCode(k200OK);
resp->setContentTypeCode(CT_TEXT_HTML);
resp->setBody("PONG");
callback(resp);
}
but when I try to call http://localhost/PING i get 404 Not Found
LOG_TRACE << "log body";
I desire above line results a line in the log file but it doesn't.
why?
( I have set the log option correctly and I run the app in the Debug mode and others log have written to log file properly.)
ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");
It is possible with METHOD_ADD to chain filters?
@thylacinelol
if you configure document_root directory and add *.html files, public can access it,
even if it's located on document_root
/docs/how-to-x.html
this is also equilevant as domain.tld[:port-if-any]/docs/how-to-y.html
open this https://drogon.org/images/drogon-concise-white.png and look https://github.com/drogonframework/drogon-website/tree/master/content/images
@thylacinelol
something like this doable with c++20
Home.h
namespace MyProject
{
namespace controllers
{
class Home
: public drogon::HttpController<Home>
{
public:
METHOD_LIST_BEGIN
ADD_METHOD_TO(Home::HomePage, "/", drogon::Get);
ADD_METHOD_TO(Home::HelloPage, "/hello", drogon::Get);
METHOD_LIST_END
void HomePage(const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr&)>&&callback);
drogon::AsyncTask HelloPage(const drogon::HttpRequestPtr req,
std::function<void(const drogon::HttpResponsePtr&)>callback);
}; // class Home
} // namespace controllers
} // namespace MyProject
Home.cc
#include "Home.h"
using namespace backendV1::controllers;
void Home::HomePage(const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr&)>&&callback)
{
// ... some logic
}
drogon::AsyncTask Home::HelloPage(const drogon::HttpRequestPtr req,
std::function<void(const drogon::HttpResponsePtr&)>callback)
{
auto client = drogon::HttpClient::newHttpClient("http://www.localhost.com:8001");
auto request = drogon::HttpRequest::newHttpRequest();
request->setMethod(drogon::Get);
request->setPath("/hello.html");
auto foo = co_await client->sendRequestCoro(request);
auto bar = foo->getBody();
std::string baz{bar};
resp = drogon::HttpResponse::newHttpResponse();
resp->setBody(baz);
callback(resp);
}
hi @an-tao, we have an issue related to LOG_DEBUG macro. When we integrate our system with an external logging system which uses syslog, as syslog has same macro it is overriding. Is it possbile to use some prefix before those macros. LOG_DEBUG, LOG_ERROR etc is very common and mostly logging libraries uses them.
The solution I can think of is to compile your app with dragon source code, then resolve the conflict by string replacing