-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_config.cpp
More file actions
46 lines (39 loc) · 1.34 KB
/
Copy pathserver_config.cpp
File metadata and controls
46 lines (39 loc) · 1.34 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
/***********************
* @file: server_config.cpp
* @author: shizuku
* @date: 2020/7/15
***********************/
#include "server_config.h"
server_config::server_config(const std::string &filename) {
boost::property_tree::ptree root;
boost::property_tree::read_json(filename, root);
port = root.get<int>("port");
auto r = root.get_child("router");
for (auto &i : r) {
router.insert_or_assign(i.first, i.second.get<std::string>(""));
}
auto e = root.get_child("expires");
for (auto &i : e) {
expires.insert_or_assign(i.first, i.second.get<std::string>(""));
}
auto ep = root.get_child("error_pages");
for (auto &i : ep) {
error_pages.insert_or_assign(i.first, i.second.get<std::string>(""));
}
auto pp = root.get_child("proxy_pass");
for (auto &i : pp) {
proxy_pass.insert_or_assign(i.first, std::map<std::string, std::string>{
{"host", i.second.get<std::string>("host")},
{"port", i.second.get<std::string>("port")},
{"url", i.second.get<std::string>("url")},
});
}
}
std::ostream &operator<<(std::ostream &o, const server_config &sc) {
o << "port: " << sc.port << "\n";
o << "router:\n";
for (auto &i:sc.router) {
o << "\t" << i.first << "\t\t" << i.second << "\n";
}
return o;
}