-
Notifications
You must be signed in to change notification settings - Fork 2
/
Server.h
54 lines (40 loc) · 1.34 KB
/
Server.h
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
#pragma once
#include <memory>
#include <vector>
#include "Routes.h"
namespace shitty {
class Server {
public:
Server();
~Server();
Server& addStaticHandler(const std::string& path, Response&& response) {
routes_.addRoute(std::make_unique<StaticRoute>(path, std::make_unique<StaticResponder>(std::move(response))));
return *this;
}
Server& addStaticHandler(const std::string& path, std::unique_ptr<StaticResponder>&& responder) {
routes_.addRoute(std::make_unique<StaticRoute>(path, move(responder)));
return *this;
}
template <typename... Args>
Server& addStaticHandler(const std::string& path, Args... args) {
routes_.addRoute(std::make_unique<StaticRoute>(path, std::make_unique<StaticResponder>(std::forward<Args>(args)...)));
return *this;
}
template <typename... Args>
Server& addHandler(const std::string& path, Args... args) {
routes_.addRoute(std::make_unique<FactoryRoute>(path, std::forward<Args>(args)...));
return *this;
}
void addRoute(std::unique_ptr<Route>&& route) {
routes_.addRoute(std::move(route));
}
void run();
int epollFD();
private:
// Config
// TODO: Move all config into a separate class.
Routes routes_;
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace shitty