Esempio n. 1
0
void Router::addRoute(const std::string& url, handler_uptr handler, route_t route, const std::string& handler_name) {
  if (url == "/")
    throw RouterException(
        "Registering for '/' is not possible, use "
        "Router::route_t::CATCH_ALL to register "
        "for all unmatched urls");
  _route[url].swap(handler);
  _route_names[url] = handler_name;
  if (route == route_t::CATCH_ALL)
    setCatchAll(_route[url].get());
}
Esempio n. 2
0
Router::handler_ptr Router::getCatchAll() const {
  if (_catch_all == nullptr)
    throw RouterException("No url was set with Router::route_t::CATCH_ALL");
  return _catch_all;
}
Esempio n. 3
0
void Router::setCatchAll(const handler_ptr handler) {
  if (_catch_all != nullptr)
    throw RouterException("Tried to set catch all when already set");
  _catch_all = handler;
}