Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    1111mp
    @1111mp
    image.png
    Assertion failed: (idx < storage_.size()), function getThreadData, file IOThreadStorage.h, line 100.
    can someone help me
    please
    thank you very much
    1111mp
    @1111mp
    Probably know the reason, here you need to use the synchronous execCommandSync method.
    An Tao
    @an-tao
    you should use the fast redis client to ensure that the storage is accessed in IO threads (not in the thread used by redis client)
    jamal rashidi
    @jamalrashidi1_twitter

    hello
    I have a problem with Trantor on Windows compiled with MSVC 2017 x64. I got the below error when running a simple TCP server using Trantor :

    ERROR SO_REUSEPORT is not supported.

    An Tao
    @an-tao
        TcpServer(EventLoop *loop,
                  const InetAddress &address,
                  const std::string &name,
                  bool reUseAddr = true,
                  bool reUsePort = true);
    you can set the last parameter to false
    5 replies
    Okami チム
    @okami.mks:matrix.org
    [m]
    installing vcpkg was a struggle, XD
    demenkovms
    @demenkovms

    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

    An Tao
    @an-tao
    did you re-cmake your project after adding this controller?
    demenkovms
    @demenkovms
    yes, of course )
    aliakbarrashidi
    @aliakbarrashidi:matrix.org
    [m]

    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.)

    An Tao
    @an-tao
    Did you set the log_level to TRACE?
    3 replies
    jamal rashidi
    @jamalrashidi1_twitter
    Is it possible to have nested drogon::HttpFilter for a request?
    I want some requests go through multiple HttpFilters.
    An Tao
    @an-tao
    ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");
    jamal rashidi
    @jamalrashidi1_twitter
    Thanks

    ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");

    It is possible with METHOD_ADD to chain filters?

    An Tao
    @an-tao
    yes
    jamal rashidi
    @jamalrashidi1_twitter
    Thanks again
    Ghasem Ramezani
    @another-ghasem
    Hi, Why the CMake files(like DrogonUtilities.cmake) are explicitly removed in the Conan recipe? How could I use functions like drogon_create_views?
    Hiderr
    @Hiderrr
    Hello, I've got a little question regarding drogon's framework usage.
    Is there any recommended way of handling HTTP requests' authorization? (Is it maybe possible to allow filters to take parameters such as an Array of required permissions? (enum values e.g.))
    Rafael Bugajewski
    @rbugajewski
    thylacinelol
    @thylacinelol
    Hi
    Is it possible to automatically route paths to static html files?
    For example, make http://localhost:3000/hello serve http://localhost:3000/hello.html if the html file exists?
    P.R.
    @prothegee

    @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
    @thylacinelol
    @prothegee yep, serving files works fine - I can access the page via domain.tld[:port]/hello.html, however, I want to remove the .html, so that you can access the filehello.html via domain.tld[:port]/hello.
    P.R.
    @prothegee

    @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);
    }
    image.png
    I didn't know that was doable till now, LOL
    P.R.
    @prothegee
    Otherwise I didn't know yet for another solution
    P.R.
    @prothegee
    image.png
    thylacinelol
    @thylacinelol
    woah nice, thanks!
    P.R.
    @prothegee
    image.png
    Hi, is anyone know how to change cookie domain name?
    aliakbarrashidi
    @aliakbarrashidi:matrix.org
    [m]
    Hi, how can I stop accepting more than particular amount of request from one origin ( based on IP or whatever else) to prevent scrapping my endpoints?
    2 replies
    headofdeveloper
    @headofdeveloper
    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.
    An Tao
    @an-tao

    Hi, is anyone know how to change cookie domain name?

    I don't think drogon sends domain name in session cookie, please confirm it via packet capturing tools.

    1 reply

    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

    Ichiro
    @HadesD

    how can I make two request not blocking each-others?
    Currently my problem:

    • request1: run with block HttpClient Request inside
    • request2: has to wait request1 completed (callback)

    How can I continue request2 without wait request1 to completed?

    Ichiro
    @HadesD
    ok, I use coro + CurrentThreadEventLoop then it solved problem
    I think you should add document to coroutines https://drogon.docsforge.com/master/coroutines/#enabling-coroutines
    add example of HttpClient also
    @an-tao
    Ichiro
    @HadesD
    Re-tested
    I 've found this, if I build drogon with ./build.sh -t , it not problem with deadlock when use coro.httpclient on controller, without -t flag, it will be trouble with deadlock
    house-mouse
    @house-mouse
    Hello Drogon folks! Thanks for your awesome work on this project! I am wondering if it's possible to have wildcards in websocket urls? Can something like WS_PATH_ADD("/session/{1}") be used and then the path parameter picked up in some way similar to how METHOD_ADD works with something like METHOD_ADD(Book::getInfo,"/{1}",Get); ? It looks like METHOD_ADD doesn't have any method like Ws akin to Get or Post to be able to catch things before websocket negotiation fully turns the request into a websocket connection, so I'm not sure where or how I might be able to grab the url early in the negotiation? Thanks for any thoughts!
    An Tao
    @an-tao
    Currently you can't do that. WebsocketController is just like HttpSimpleController. it doesn't support parameters mapping. you can add your parameters to the query string or the body of requests.
    house-mouse
    @house-mouse
    Thanks for the quick reply!
    P.R.
    @prothegee

    Hi everyone,
    what is the equivalent of:

    auto cmd = R"(
        update public.account_verification_email set token_expired=true where email=$1;
    )";
    db->execSqlAsyncFuture(cmd, u_email);

    in drogon::orm ?

    <br>

    I tried:

    orm::Mapper<AccountVerificationEmail> aveMP(db);
    
    aveMP.updateFutureBy(
        AccountVerificationEmail::Cols::_token_expired,
            orm::Criteria(AccountVerificationEmail::Cols::_email,
            orm::CompareOperator::Like, u_email),
                true);

    but gets error:

    [build] /home/prg/backend/beCPP/db/postgresdb.h:326:53: note:   cannot convert ‘drogon_model::database_name::AccountVerificationEmail::Cols::_token_expired’ (type ‘const string’ {aka ‘const std::__cxx11::basic_string<char>’}) to type ‘const std::vector<std::__cxx11::basic_string<char> >&’
    [build]   326 |                     AccountVerificationEmail::Cols::_token_expired,
    [build]       |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

    these column was actually boolean.

    Can someone correct me which part should be change?

    Raw sql command is fine, but I want to maximize using drogon orm.

    An Tao
    @an-tao
    The first parameter of the update method is a vector for updating multiple columns, try this:
    aveMP.updateFutureBy(
        {AccountVerificationEmail::Cols::_token_expired},
            orm::Criteria(AccountVerificationEmail::Cols::_email,
            orm::CompareOperator::Like, u_email),
                true);
    1 reply