craw cpp自定义中间

直接上代码:

#include 
#include 
#include 

struct AdminAreaGuard
{
    struct context
    {};

    void before_handle(crow::request& req, crow::response& res, context& ctx){
        std::cout << "before_handle: "<< req.remote_ip_address << std::endl;
        auto auth = req.headers.find("auth");
        if(auth != req.headers.end()){
            std::cout << "auth: " << auth->second << std::endl;
        }
    }
    void after_handle(crow::request& req, crow::response& res, context& ctx){
        std::cout << "after_handle" << std::endl;
    }
};

int main() {

    crow::App<AdminAreaGuard> app;

    CROW_ROUTE(app, "/")([]() {
                        return "Hello world!";
                    });

    app.port(9090).multithreaded().run();

    std::cout << "Hello, World!" << std::endl;
    return 0;
}

你可能感兴趣的:(crow,cpp,c++)