Where do I put code for dragon to do some custom automation for the following? :
Example:
Client from website presses a button to read some data from the local PostgreSQL database.
Dragon will listen for requests using websockets.
Then dragon will parse the JSON data that was requested from client.
Dragon needs to know what this parsed JSON data request means.
Parsed JSON data says to fetch some data from local PostgreSQL database.
After dragon fetches data from local PostgreSQL database, dragon needs to send this fetched data to the client using websocket.
The above can be easily done using node.js But how can the above objectives be done using dragon?
Are there any tutorials other than WiKi and docsforge?
I find WiKi and docsforge a bit too advanced and complicated for a beginner to understand.
Thanks
Hey Guys
Just a simple question!
this is a test for me!
I wanna bind a callback to specific port!
in other words, I need to make conditions on port numbers to send related response to client that sends request to specific port!
as you can see, we can just add some listeners having ip , port!
But addListener method has no any callback args!
drogon::app().addListener("0.0.0.0",20001);
drogon::app().addListener("0.0.0.0",20002);
drogon::app().addListener("0.0.0.0",20003);
drogon::HttpAppFramework::instance().registerHandler("/index",
[=](const drogon::HttpRequestPtr &req ,
std::function<void (const drogon::HttpResponsePtr &)> &&callback)
{
if (req ->port == 20001)
{
auto resp = drogon::HttpResponse::newFileResponse("/path/to/img01.jpg", "", drogon::ContentType::CT_IMAGE_JPG);
callback(resp);
}
else if (req ->port == 20002)
{
auto resp = drogon::HttpResponse::newFileResponse("/path/to/img02.jpg", "", drogon::ContentType::CT_IMAGE_JPG);
callback(resp);
}
else if (req ->port == 20003)
{
auto resp = drogon::HttpResponse::newFileResponse("/path/to/img03.jpg", "", drogon::ContentType::CT_IMAGE_JPG);
callback(resp);
}
});
in the top example, req->port has error because req has no any port member!
so I don't know how can I set conditions or bind callbacks on ports!
All The Best,
Hadi
/usr/src/drogon/lib/inc/drogon/IOThreadStorage.h:100: drogon::IOThreadStorage<C>::ValueType& drogon::IOThreadStorage<C>::getThreadData() [with C = std::shared_ptr<drogon::HttpResponse>; drogon::IOThreadStorage<C>::ValueType = std::shared_ptr<drogon::HttpResponse>]: Assertion `idx < storage_.size()' failed.
/usr/src/drogon/lib/inc/drogon/IOThreadStorage.h:100: drogon::IOThreadStorage<C>::ValueType& drogon::IOThreadStorage<C>::getThreadData() [with C = std::shared_ptr<drogon::HttpResponse>; drogon::IOThreadStorage<C>::ValueType = std::shared_ptr<drogon::HttpResponse>]: Assertion `idx < storage_.size()' failed.
The error usually means the done callback is not in an IO threads of drogon. if you use dbClients, please use the Fast database clients, because it uses the IO threads.
how to disable Ctrl+C feature? when I press Ctrl+C it shouldn't quit. It shouldn't handle anything like that.
/// Disable the handling of SIGTERM signal.
/**
* Enabled by default.
*
* @note
* This operation can be performed by an option in the configuration file.
* When disabled setTermSignalHandler() is useless
*/
virtual HttpAppFramework &disableSigtermHandling() = 0;