38 [&stdHeaders =
this->stdHeaders, &stdCookies =
this->stdCookies, &connectionState
= this->defaultConnectionState]
MIDDLEWARE(
40 if (req->method ==
"GET") {
41 LOG(DEBUG) << res->getSocketContext()->getSocketConnection()->getConnectionName()
42 <<
" Express StaticMiddleware correct method: " << req->method;
45 res->set(
"Connection",
"close");
47 res->set(
"Connection",
"keep-alive");
51 for (
auto& [value, options] : stdCookies) {
52 res->cookie(value, options.getValue(), options.getOptions());
56 LOG(ERROR) << res->getSocketContext()->getSocketConnection()->getConnectionName()
57 <<
" Express StaticMiddleware wrong method: " << req->method;
60 res->set(
"Connection",
"close");
62 res->set(
"Connection",
"keep-alive");
68 if (req->url ==
"/") {
69 LOG(INFO) << res->getSocketContext()->getSocketConnection()->getConnectionName()
70 <<
" Express StaticMiddleware Redirecting: " << req->url <<
" -> " <<
"/index.html'";
71 res->redirect(308,
"/index.html");
77 res->sendFile(root + req->url, [&root, req, res](
int ret) {
79 LOG(INFO) << res->getSocketContext()->getSocketConnection()->getConnectionName()
80 <<
" Express StaticMiddleware: GET " << req->url +
" -> " << root + req->url;
82 PLOG(ERROR) << res->getSocketContext()->getSocketConnection()->getConnectionName() <<
" Express StaticMiddleware "
83 << req->url +
" -> " << root + req->url;
85 res->status(404).end();
131 static std::map<
const std::string, std::shared_ptr<
class StaticMiddleware>> staticMiddlewares;
133 if (!staticMiddlewares.contains(root)) {
134 staticMiddlewares[root] = std::shared_ptr<StaticMiddleware>(
new StaticMiddleware(root));
137 return *staticMiddlewares[root];