-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cc
46 lines (39 loc) · 1.21 KB
/
main.cc
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
37
38
39
40
41
42
43
44
45
46
#include <drogon/drogon.h>
#include "controllers/CsrfTokenCtrl.h"
#include "app_helpers/Auth.hpp"
#include "app_helpers/ApiResponse.hpp"
int main() {
//Set HTTP listener address and port
// drogon::app().addListener("0.0.0.0",80);
//Load config file
drogon::app().loadConfigFile("./config.json");
drogon::app().registerPreRoutingAdvice(
[](const auto &req, auto &&fcb, auto &&fccb)
{
using namespace drogon;
switch (req->method())
{
case HttpMethod::Post:
case HttpMethod::Patch:
case HttpMethod::Put:
{
// CSRF check
if (!CsrfTokenCtrl::verify(req))
{
//Check failed
auto res = HttpResponse::newHttpResponse();
res->setStatusCode(k403Forbidden);
res->setBody("CSRF Token Mismatch");
fcb(res);
return;
}
}
default:
// Passed
fccb();
}
});
//Run HTTP framework,the method will block in the internal event loop
drogon::app().run();
return 0;
}