Skip to content

Options Request - How to Setup #2188

Discussion options

You must be logged in to vote

Hi Paul.
I found the best solution to manage all OPTIONS requests from main.cc:

drogon::app()
        .registerPreRoutingAdvice(
            [](const drogon::HttpRequestPtr &req, drogon::FilterCallback &&stop,
               drogon::FilterChainCallback &&pass)
            {
              if (!req->path().starts_with("/api") ||
                  req->method() != drogon::Options)
              {
                pass();
                return;
              }

              auto resp = drogon::HttpResponse::newHttpResponse();
              resp->addHeader("Access-Control-Allow-Origin", "*");
              stop(resp);
            })
        .registerPostHandlingAdvice(
            [](const dr…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by paul-marquick
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants