-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (39 loc) · 1.18 KB
/
main.cpp
File metadata and controls
46 lines (39 loc) · 1.18 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
#include <regex>
#include "Directory.h"
#include "Logger.h"
#include "Request.h"
#include "Response.h"
#include "Server.h"
#include "exception"
#include "iostream"
auto main() -> int {
try {
static constexpr int DEFAULT_PORT = 8080;
simple_http_server::Server server("0.0.0.0", DEFAULT_PORT,
simple_http_server::DEBUG);
server.MapUrl(
"/plain",
[](const simple_http_server::Request&) -> auto {
return simple_http_server::Response(
simple_http_server::Response::HttpStatusCodes::OK,
"Hello world in plain text");
},
true);
server.MapUrl("/", [](const simple_http_server::Request&) -> auto {
return simple_http_server::Server::Render("index.html");
});
server.MapDirectory(
"/dir",
simple_http_server::Directory(
"./", {}, simple_http_server::Directory::AllowType::WHITELIST,
{std::regex("^.*.log$")}));
server.Start();
return 0;
} catch (const std::exception& exc) {
std::cerr << "Fatal error: " << exc.what() << '\n';
return 1;
} catch (...) {
std::cerr << "Unknown fatal error\n";
return 1;
}
}