-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cpp
More file actions
70 lines (52 loc) · 1.8 KB
/
Copy pathapp.cpp
File metadata and controls
70 lines (52 loc) · 1.8 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
#include <iostream>
#include <cstdlib>
#include <RWEB.h>
static rweb::HTMLTemplate homePage(const rweb::Request r);
void atexit_handler();
int main()
{
if (!rweb::init(true, 1))
{
std::cout << "Failed to initialize RWEB!\n";
return -1;
}
const int atex = std::atexit(atexit_handler);
if (atex)
{
std::cout << rweb::colorize(rweb::RED) << "Failed to register atexit!\n" << rweb::colorize(rweb::NC);
rweb::closeServer();
return -1;
}
rweb::setPort(4221);
rweb::setProfilingMode(true);
rweb::addRoute("/", [](const rweb::Request r){return rweb::redirect("/index");});
rweb::addRoute("/index", &homePage);
rweb::addRoute("/abort", [](const rweb::Request r){return rweb::abort(rweb::HTTP_401);});
rweb::setErrorHandler(404, [](const rweb::Request r){return rweb::redirect("/index");});
rweb::setErrorHandler(401, &homePage);
rweb::addResource("/style.css", "style.css", rweb::MIME::CSS);
std::cout << "----------SERVER CONFIG----------\n";
std::cout << "Debug: " << (rweb::getDebugState() ? "ENABLED" : "DISABLED") << "\n";
std::cout << "Resource path: " << rweb::getResourcePath() << "\n";
std::cout << "Port: " << rweb::getPort() << "\n";
std::cout << "----------SERVER CONFIG----------\n\n";
std::cout << "Server started at: " << "127.0.0.1:" << rweb::getPort() << "\n\n";
std::cout << "----------SERVER LOGS----------\n";
if (!rweb::startServer(2))
{
rweb::closeServer();
return -1;
}
return 0;
}
void atexit_handler()
{
std::cout << "\n----------SERVER STOPPED----------\n";
}
static rweb::HTMLTemplate homePage(const rweb::Request r)
{
rweb::HTMLTemplate temp = rweb::createTemplate("index.html", rweb::HTTP_200);
nlohmann::json json = nlohmann::json::parse(rweb::getFileString("../menu.json"));
temp.renderJSON(json);
return temp;
}