FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expresscpp/example/middleware_logger_like.cpp at master · hpsware/expresscpp · GitHub
hpsware
/
expresscpp
Public
forked from
expresscpp/expresscpp
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
expresscpp
/
example
/
middleware_logger_like.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (29 loc) · 1.15 KB
Breadcrumbs
expresscpp
/
example
/
middleware_logger_like.cpp
Copy path
File metadata and controls
36 lines (29 loc) · 1.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
include
"
expresscpp/console.hpp
"
#
include
"
expresscpp/date.hpp
"
#
include
"
expresscpp/expresscpp.hpp
"
using
namespace
expresscpp
;
int
main
() {
ExpressCpp app;
auto
LogMiddleware = [&](
auto
req,
auto
/*
res
*/
,
auto
next) {
std::cerr <<
"
[
"
<<
Date::getTime
() <<
"
]
"
<<
"
access to path
"
<<
"
\"
"
<< req->
getPath
() <<
"
\"
"
<< std::endl;
next
();
};
app.
Use
(LogMiddleware);
app.
Get
(
"
/users/john
"
, [&](
auto
/*
req
*/
,
auto
res,
auto
/*
next
*/
) { res->
Send
(
"
hello john!
"
); });
app.
Get
(
"
/users/steve
"
, [&](
auto
/*
req
*/
,
auto
res,
auto
/*
next
*/
) { res->
Send
(
"
hello steve!
"
); });
constexpr
uint16_t
port =
8081
;
app.
Listen
(port,
[&](
auto
ec) {
if
(ec) {
std::cerr <<
"
ERROR:
"
<< ec.
message
() << std::endl;
std::cerr <<
"
exiting...
"
<< std::endl;
exit
(
1
);
}
std::cout <<
fmt::format
(
R"(
you can try now: "curl http://localhost:{}/users/john"
)"
, port) << std::endl;
std::cout <<
fmt::format
(
R"(
and : "curl http://localhost:{}/users/steve"
)"
, port) << std::endl;
})
.
Run
();
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL