Skip to content

Commit

Permalink
-updated router;
Browse files Browse the repository at this point in the history
-updated examples to support changes in hot_teacup library;
  • Loading branch information
kamchatka-volcano committed Aug 22, 2024
1 parent 9556fd6 commit 52b73c7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SealLake_Bundle(
SealLake_Bundle(
NAME asyncgi_whaleroute
GIT_REPOSITORY https://github.com/kamchatka-volcano/whaleroute.git
GIT_TAG v3.1.0
GIT_TAG dev
DESTINATION include/asyncgi/detail/external
DIRECTORIES include/whaleroute
TEXT_REPLACEMENTS
Expand Down
11 changes: 5 additions & 6 deletions examples/example_guestbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ http::Response showLoginPage(const http::Request&)
http::Response loginAdmin(const http::Request& request)
{
if (request.formField("login") == "admin" && request.formField("passwd") == "12345")
return {http::Redirect{"/"}, {http::Cookie("admin_id", "ADMIN_SECRET")}};
return {http::Redirect{"/"}, http::Cookies{{"admin_id", "ADMIN_SECRET"}}};
else
return http::Redirect{"/login"};
}

http::Response logoutAdmin(const http::Request&)
{
return {http::Redirect{"/"}, {http::Cookie("admin_id", "")}};
return {http::Redirect{"/"}, http::Cookies{{"admin_id", ""}}};
}

struct GuestBookMessage {
Expand Down Expand Up @@ -193,12 +193,11 @@ int main()
auto io = asyncgi::IO{4};
auto state = GuestBookState{};
auto router = asyncgi::Router<RouteContext>{io};
router.route(asyncgi::rx{".*"}).process(authorizeAdmin);
router.route("{path}").process(authorizeAdmin);
router.route("/", http::RequestMethod::Get).process(showGuestBookPage(state));
router.route("/", http::RequestMethod::Post).process(addMessage(state));
router.route(asyncgi::rx{"/delete/(.+)"}, http::RequestMethod::Post, AccessRole::Admin)
.process(removeMessage(state));
router.route(asyncgi::rx{"/delete/(.+)"}, http::RequestMethod::Post, AccessRole::Guest)
router.route("/delete/{str}/", http::RequestMethod::Post, AccessRole::Admin).process(removeMessage(state));
router.route("/delete/{str}/", http::RequestMethod::Post, AccessRole::Guest)
.set(http::ResponseStatus::_401_Unauthorized);
router.route("/login", http::RequestMethod::Get, AccessRole::Guest).process(showLoginPage);
router.route("/login", http::RequestMethod::Post, AccessRole::Guest).process(loginAdmin);
Expand Down
4 changes: 2 additions & 2 deletions examples/example_route_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct LoginPageAuthorize {
{
if (context.role == AccessRole::Guest) {
if (request.formField("login") == "admin" && request.formField("passwd") == "12345")
return {http::Redirect{"/"}, {asyncgi::http::Cookie("admin_id", "ADMIN_SECRET")}};
return {http::Redirect{"/"}, asyncgi::http::Cookies{{"admin_id", "ADMIN_SECRET"}}};
else
return http::Redirect{"/login"};
}
Expand All @@ -59,7 +59,7 @@ int main()
{
auto io = asyncgi::IO{4}; //4 threads processing requests
auto router = asyncgi::Router<RouteContext>{io};
router.route(asyncgi::rx{".*"}).process<AdminAuthorizer>();
router.route("{path}").process<AdminAuthorizer>();
router.route("/").process(
[](const http::Request&, RouteContext& context) -> http::Response
{
Expand Down
2 changes: 1 addition & 1 deletion examples/example_route_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main()
{
auto io = asyncgi::IO{4};
auto router = asyncgi::Router<RouteContext>{io};
router.route(asyncgi::rx{".*"}).process<AdminAuthorizer>();
router.route("{path}").process<AdminAuthorizer>();
router.route("/").process(
[](const http::Request&, RouteContext& context) -> http::Response
{
Expand Down
2 changes: 1 addition & 1 deletion examples/example_route_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int main()
auto router = asyncgi::Router{io};
router.route("/", http::RequestMethod::Get).process<GuestBookPage>(state);
router.route("/", http::RequestMethod::Post).process<GuestBookAddMessage>(state);
router.route(asyncgi::rx{"/delete/(.+)"}, http::RequestMethod::Post).process<GuestBookRemoveMessage>(state);
router.route("/delete/{str}", http::RequestMethod::Post).process<GuestBookRemoveMessage>(state);
router.route().set(http::ResponseStatus::_404_Not_Found, "Page not found");

auto server = asyncgi::Server{io, router};
Expand Down
2 changes: 1 addition & 1 deletion examples/example_route_params_user_defined_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main()
auto router = asyncgi::Router{io};
router.route("/", http::RequestMethod::Get).process<GuestBookPage>(state);
router.route("/", http::RequestMethod::Post).process<GuestBookAddMessage>(state);
router.route(asyncgi::rx{"/delete/(.+)"}, http::RequestMethod::Post).process<GuestBookRemoveMessage>(state);
router.route("/delete/{str}", http::RequestMethod::Post).process<GuestBookRemoveMessage>(state);
router.route().set(http::ResponseStatus::_404_Not_Found, "Page not found");

auto server = asyncgi::Server{io, router};
Expand Down
2 changes: 0 additions & 2 deletions include/asyncgi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
namespace asyncgi {
using _ = whaleroute::_;

using rx = whaleroute::rx;
namespace string_literals = whaleroute::string_literals;
using TrailingSlashMode = whaleroute::TrailingSlashMode;
template<int minSize = 0>
using RouteParameters = whaleroute::RouteParameters<minSize>;
Expand Down

0 comments on commit 52b73c7

Please sign in to comment.