Fix up router, add .post route

This commit is contained in:
Alex Hultman
2018-10-03 19:36:46 +02:00
parent d4ca158495
commit 7d06bef485
5 changed files with 48 additions and 19 deletions
+9 -1
View File
@@ -111,7 +111,7 @@ private:
typename uWS::HttpContextData<SSL>::UserData userData = {
(HttpResponse<SSL> *) s, httpRequest
};
httpContextData->router.route("get", 3, httpRequest->getUrl().data(), httpRequest->getUrl().length(), &userData);
httpContextData->router.route(httpRequest->getMethod().data(), httpRequest->getMethod().length(), httpRequest->getUrl().data(), httpRequest->getUrl().length(), &userData);
// here we can be closed and in shutdown?
@@ -220,6 +220,14 @@ public:
});
}
void onPost(std::string pattern, std::function<void(uWS::HttpResponse<SSL> *, uWS::HttpRequest *)> handler) {
HttpContextData<SSL> *httpContextData = getSocketContextData();
httpContextData->router.add("post", pattern.c_str(), [handler](typename HttpContextData<SSL>::UserData *user, auto *args) {
handler(user->httpResponse, user->httpRequest);
});
}
void onUnhandled(std::function<void(uWS::HttpResponse<SSL> *, uWS::HttpRequest *)> handler) {
HttpContextData<SSL> *httpContextData = getSocketContextData();