-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (43 loc) · 1.9 KB
/
main.cpp
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
#include <string>
#include <FlowUtils/FlowArgParser.h>
#include <FlowHttp/Request.h>
#include <thread>
#include <FlowUtils/WorkerPool.h>
#include <FlowHttp/routes/Router.h>
#include <FlowHttp/routes/FileNotFound.h>
#include <FlowHttp/routes/InfoRoute.h>
#include <FlowHttp/routes/GetRoute.h>
#include <FlowHttp/routes/GetBrotliRoute.h>
#include <FlowHttp/routes/ValidateRoute.h>
#include <FlowHttp/routes/IfModifiedSince.h>
#include <FlowHttp/routes/ListFilesBack.h>
#include <FlowHttp/FlowHttp3.h>
#include <memory>
#include <FlowHttp/util/ArgParserUtil.h>
int main(int argc, char *argv[]) {
FlowArgParser fap = ArgParserUtil::defaultArgParser();;
fap.parse("localhost 1337 .");
fap.parse(argc, argv);
std::string address = fap.getString("address");
std::string port = fap.getString("port");
std::string path = fap.getString("path");
FlowString::replaceAll(path, "\\", "/");
LOG_INFO << "Listening on: " << address << ":" << port;
LOG_INFO << "Path: " << path;
size_t threadCount = fap.hasOption("threads") ? std::stoul(fap.getString("threads"), nullptr, 10) :
std::thread::hardware_concurrency() * 2;
const std::string dh = fap.getString("dh");
const std::string key = fap.getString("key");
const std::string cert = fap.getString("cert");
Router router;
router.addRoute(std::make_shared<InfoRoute>());
router.addRoute(std::make_shared<ValidateRoute>(std::set<std::string> ({"GET"})));
router.addRoute(std::make_shared<IfModifiedSince>(path));
router.addRoute(std::make_shared<GetBrotliRoute>(path));
router.addRoute(std::make_shared<GetRoute>(path));
router.addRoute(std::make_shared<ListFilesBack>(path));
router.addRoute(std::make_shared<FileNotFound>());
FlowHttp3 flowHttp (address, port, router, threadCount, dh, key, cert);
flowHttp.Run();
return EXIT_SUCCESS;
}