-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (58 loc) · 1.2 KB
/
main.cpp
File metadata and controls
75 lines (58 loc) · 1.2 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include "HttpRequest.h"
#include "HttpApplication.h"
#include "RequestHandler.h"
#include "HttpServer.h"
#include "HttpResponse.h"
#include "Logger.h"
#include "HttpClient.h"
#include <map>
#include <thread>
#include <chrono>
class Main : public RequestHandler
{
public:
void get()
{
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
write("data\n");
}
};
class Html : public RequestHandler
{
void get()
{
render("web.html");
}
};
class Index : public RequestHandler
{
void get()
{
render("index.html");
}
};
class Hello : public RequestHandler
{
void get()
{
write("Hello World\n");
}
};
int main()
{
std::map<std::string, std::shared_ptr<Utils::iHandler>> Handlers;
Handlers = {
{"/", Utils::make_handler<Main>() },
{"/web", Utils::make_handler<Html>() },
{"/hello", Utils::make_handler<Hello>() },
{"/index", Utils::make_handler<Index>() }
};
HttpApplication app(Handlers);
HttpServer server(app);
server.bind(8081);
server.listen(1000);
std::cout<<"Starting server...\n"<<std::endl;
server.start();
return 0;
}