rsgit /cpp-webA hyper-hyperfast web frontend for git repositories written in Rust.
tree/src/main.cpp
main.cpp77 lines · 1.9 KiB
1#include "ContentManager.hpp"
2#include "EventManager.hpp"
3#include "Filesystem.hpp"
4#include "TemplateManager.hpp"
5
6#include "content/blog/Blog.hpp"
7#include "content/static/Static.hpp"
8
9#include <event2/buffer.h>
10
11#include <inja/inja.hpp>
12#include <iostream>
13
14int main(int argc, char ** argv)
15{
16 std::string wwwroot = "./wwwroot";
17 char const * host = "127.0.0.1";
18 uint16_t port = 9000;
19
20 if (argc <= 1 || argc > 5)
21 {
22 std::cout << "usage: cpp-web [HOST] [PORT] [WWWROOT]" << std::endl << std::endl;
23 if (argc > 5)
24 {
25 return 1;
26 }
27 }
28
29 if (argc > 1)
30 {
31 host = argv[1];
32 }
33 if (argc > 2)
34 {
35 port = atoi(argv[2]);
36 }
37 if (argc > 3)
38 {
39 wwwroot = argv[3];
40 }
41
42 std::shared_ptr<TemplateManager> tmgr = std::make_shared<TemplateManager>();
43 std::shared_ptr<ContentManager> cmgr = std::make_shared<ContentManager>();
44 cmgr->SetTemplateSystem(tmgr);
45
46 {
47 std::shared_ptr<Filesystem> static_fs = std::make_shared<Filesystem>();
48 std::cout << "Static fs: " << wwwroot + "/static" << std::endl;
49 static_fs->Scan(wwwroot + "/static", {"html", "tmpl"}, true);
50
51 cmgr->RegisterModule(std::make_shared<Static>("/static", static_fs));
52 }
53
54 {
55 Filesystem dynamic_fs;
56 std::cout << "Dynamic fs: " << wwwroot << std::endl;
57 dynamic_fs.Scan(wwwroot, {"html", "tmpl"}, false);
58
59 tmgr->ParseTemplates(dynamic_fs);
60 }
61
62 cmgr->RegisterModule(std::make_shared<Markdown>("/", wwwroot + "/pages", "index.html"));
63 cmgr->RegisterModule(std::make_shared<Blog>("/blog", wwwroot + "/blog", "blog/index.html"));
64 cmgr->RegisterModule(std::make_shared<Blog>("/inherit", wwwroot + "/blog", "inherit/index.html"));
65
66 if (cmgr->InitAll() == false)
67 {
68 std::cout << "InitAll() failed." << std::endl;
69 return 1;
70 }
71
72 EventManager evmgr(cmgr);
73 evmgr.Init(host, port);
74
75 // cmgr.ShutdownAll();
76}
77