-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (37 loc) · 1.47 KB
/
main.cpp
File metadata and controls
52 lines (37 loc) · 1.47 KB
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
47
48
49
50
51
52
#include "booking/controller/Controller.h"
#include "include/httplib.h"
#include "include/dotenv-cpp.h"
#include "utils/Utils.h"
#include <iostream>
#include <nlohmann/json.hpp>
using namespace std;
using namespace httplib;
using json = nlohmann::json;
int main() {
dotenv::init();
Server svr;
// Preflight routes
svr.Options(R"(\*)", [](const auto& req, auto& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization");
res.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, POST, HEAD");
});
svr.Options("/booking/create", [](const auto& req, auto& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Allow", "GET, POST, HEAD, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization");
res.set_header("Access-Control-Allow-Methods", "OPTIONS, GET, POST, HEAD");
});
svr.Get("/ping", [](const Request &req, Response &res) {
res.set_content("Pong", "text/plain");
cout << "Sended..." << endl;
});
BookingController booking(svr);
auto exceptionHandler =
std::bind(&Utils::ExceptionHandler, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
svr.set_exception_handler(exceptionHandler);
svr.listen("0.0.0.0", 3000);
return 0;
}