SNode.C
Loading...
Searching...
No Matches
RootRoute.cpp
Go to the documentation of this file.
1
/*
2
* SNode.C - a slim toolkit for network communication
3
* Copyright (C) Volker Christian <me@vchrist.at>
4
* 2020, 2021, 2022, 2023, 2024, 2025
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published
8
* by the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#
include
"express/RootRoute.h"
21
22
#
include
"express/Controller.h"
23
#
include
"express/Response.h"
24
#
include
"express/dispatcher/ApplicationDispatcher.h"
25
#
include
"express/dispatcher/MiddlewareDispatcher.h"
26
#
include
"express/dispatcher/RouterDispatcher.h"
27
28
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
29
30
#
include
<
functional
>
31
#
include
<
memory
>
32
33
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
34
35
#
define
DEFINE_ROOTROUTE_REQUESTMETHOD
(
METHOD
,
HTTP_METHOD
)
36
Route
&
RootRoute
::
METHOD
(
const
RootRoute
&
rootRoute
)
const
{
37
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
"/"
,
rootRoute
.
getDispatcher
(
)
)
;
38
}
39
Route
&
RootRoute
::
METHOD
(
const
std
::
string
&
relativeMountPath
,
const
RootRoute
&
rootRoute
)
const
{
40
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
relativeMountPath
,
rootRoute
.
getDispatcher
(
)
)
;
41
}
42
Route
&
RootRoute
::
METHOD
(
const
std
::
string
&
relativeMountPath
,
43
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
Request
>
&
,
const
std
::
shared_ptr
<
Response
>
&
,
Next
&
)
>
&
lambda
)
44
const
{
45
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
relativeMountPath
,
std
::
make_shared
<
dispatcher
::
MiddlewareDispatcher
>
(
lambda
)
)
;
46
}
47
Route
&
RootRoute
::
METHOD
(
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
Request
>
&
,
const
std
::
shared_ptr
<
Response
>
&
,
Next
&
)
>
&
lambda
)
48
const
{
49
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
"/"
,
std
::
make_shared
<
dispatcher
::
MiddlewareDispatcher
>
(
lambda
)
)
;
50
}
51
Route
&
RootRoute
::
METHOD
(
const
std
::
string
&
relativeMountPath
,
52
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
Request
>
&
,
const
std
::
shared_ptr
<
Response
>
&
)
>
&
lambda
)
const
{
53
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
relativeMountPath
,
std
::
make_shared
<
dispatcher
::
ApplicationDispatcher
>
(
lambda
)
)
;
54
}
55
Route
&
RootRoute
::
METHOD
(
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
Request
>
&
,
const
std
::
shared_ptr
<
Response
>
&
)
>
&
lambda
)
const
{
56
return
routes
(
)
.
emplace_back
(
HTTP_METHOD
,
"/"
,
std
::
make_shared
<
dispatcher
::
ApplicationDispatcher
>
(
lambda
)
)
;
57
}
58
59
namespace
express {
60
61
std
::
shared_ptr
<
dispatcher
::
RouterDispatcher
>
RootRoute
::
getDispatcher
()
const
{
62
return
std::dynamic_pointer_cast<dispatcher::RouterDispatcher>(dispatcher);
63
}
64
65
std
::
list
<
Route
>&
RootRoute
::
routes
()
const
{
66
return
std::dynamic_pointer_cast<dispatcher::RouterDispatcher>(dispatcher)->getRoutes();
67
}
68
69
void
RootRoute
::
dispatch
(
Controller
&& controller) {
70
controller.setRootRoute(
this
);
71
72
dispatch
(
controller
)
;
73
}
74
75
void
RootRoute
::
dispatch
(
Controller
& controller) {
76
if
(!Route::dispatch(controller,
""
)) {
77
if
(
strict
) {
78
controller.getResponse()->sendStatus(404);
79
}
else
if
(controller.laxRouting() && !Route::dispatch(controller,
""
)) {
80
controller.getResponse()->sendStatus(404);
81
}
82
}
83
}
84
85
DEFINE_ROOTROUTE_REQUESTMETHOD
(use,
"use"
)
86
DEFINE_ROOTROUTE_REQUESTMETHOD
(all,
"all"
)
87
DEFINE_ROOTROUTE_REQUESTMETHOD
(get,
"GET"
)
88
DEFINE_ROOTROUTE_REQUESTMETHOD
(put,
"PUT"
)
89
DEFINE_ROOTROUTE_REQUESTMETHOD
(post,
"POST"
)
90
DEFINE_ROOTROUTE_REQUESTMETHOD
(del,
"DELETE"
)
91
DEFINE_ROOTROUTE_REQUESTMETHOD
(connect,
"CONNECT"
)
92
DEFINE_ROOTROUTE_REQUESTMETHOD
(options,
"OPTIONS"
)
93
DEFINE_ROOTROUTE_REQUESTMETHOD
(trace,
"TRACE"
)
94
DEFINE_ROOTROUTE_REQUESTMETHOD
(patch,
"PATCH"
)
95
DEFINE_ROOTROUTE_REQUESTMETHOD
(head,
"HEAD"
)
96
97
}
// namespace express
DEFINE_ROOTROUTE_REQUESTMETHOD
#define DEFINE_ROOTROUTE_REQUESTMETHOD(METHOD, HTTP_METHOD)
Definition
RootRoute.cpp:35
express::Controller
Definition
Controller.h:44
express::RootRoute
Definition
RootRoute.h:58
express::RootRoute::dispatch
void dispatch(Controller &&controller)
Definition
RootRoute.cpp:69
express::RootRoute::dispatch
void dispatch(Controller &controller)
Definition
RootRoute.cpp:75
express::RootRoute::routes
std::list< Route > & routes() const
Definition
RootRoute.cpp:65
express::RootRoute::strict
bool strict
Definition
RootRoute.h:82
express::RootRoute::getDispatcher
std::shared_ptr< dispatcher::RouterDispatcher > getDispatcher() const
Definition
RootRoute.cpp:61
express
RootRoute.cpp
Generated on Mon Feb 10 2025 20:21:04 for SNode.C by
1.11.0