Modify the method to generate the 404 page (#240)

This commit is contained in:
An Tao 2019-09-11 15:14:40 +08:00 committed by GitHub
parent 1e83a5cc4e
commit fff40952a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -15,7 +15,12 @@
*/
#include <drogon/DrTemplate.h>
namespace drogon
{
/**
* @brief This class is used by the drogon to generate the 404 page. Users don't
* use this class directly.
*/
class NotFound : public drogon::DrTemplate<NotFound>
{
public:
@ -23,3 +28,4 @@ class NotFound : public drogon::DrTemplate<NotFound>
virtual ~NotFound(){};
virtual std::string genText(const drogon::HttpViewData &) override;
};
} // namespace drogon

View File

@ -78,8 +78,13 @@ HttpResponsePtr HttpResponse::newNotFoundResponse()
std::call_once(once, []() {
HttpViewData data;
data.insert("version", getVersion());
notFoundResp = HttpResponse::newHttpViewResponse("NotFound", data);
notFoundResp =
HttpResponse::newHttpViewResponse("drogon::NotFound", data);
notFoundResp->setStatusCode(k404NotFound);
notFoundResp->setExpiredTime(0);
auto str = static_cast<HttpResponseImpl *>(notFoundResp.get())
->renderToString();
LOG_TRACE << *str;
});
return notFoundResp;
}