[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/expresscpp/expresscpp/master/example/router.cpp [Back]  [Original]

#include "expresscpp/console.hpp"
#include "expresscpp/expresscpp.hpp"

using namespace expresscpp;

int main() {
  ExpressCpp app;

  app.Get("/a", [](auto /*req*/, auto res, auto /*next*/) { res->Send("get_a"); });
  app.Get("/b", [](auto /*req*/, auto res, auto /*next*/) { res->Send("get_b"); });

  auto router = app.GetRouter();
  router->Use([](auto req, auto res, auto next) {
    if (req->getHeader("Authorization") == "secret_token") {
      return next();
    }
    res->SetStatus(401);
    res->Send("Access denied");
  });
  router->Get("/a", [](auto /*req*/, auto res, auto /*next*/) { res->Send("get_api_v0_users_a"); });
  router->Get("/b", [](auto /*req*/, auto res, auto /*next*/) { res->Send("get_api_v0_users_b"); });

  app.Use("/api/v0/users", router);

  constexpr uint16_t port = 8081;

  app.Listen(port,
             [&](auto ec) {
               if (ec) {
                 std::cerr 

Web Proxy Viewer  |  New URL  |  Original Page