提交 39f9425d authored 作者: blu's avatar blu

init

上级 38c6dd23
......@@ -19,6 +19,7 @@ class HttpSrv{
private:
Server svr;
json config;
json info;
void setMonitorThread() {
......@@ -29,13 +30,30 @@ class HttpSrv{
void run(){
setMonitorThread();
// get config
svr.Get("/config", [](const Request& req, Response& res){
json rep = R"({"code":0, "msg":"hello"})"_json;
res.set_content(rep.dump(), "text/json");
svr.Get("/info", [this](const Request& req, Response& res){
LVDB::getSn(this->info);
res.set_content(this->info.dump(), "text/json");
});
svr.Post("/config", [](const Request& req, Response& res){
svr.Get("/config", [this](const Request& req, Response& res){
LVDB::getSn(this->info);
LVDB::getLocalConfig(this->config);
res.set_content(this->config.dump(), "text/json");
});
svr.Post("/config", [this](const Request& req, Response& res){
try{
json newConfig = json::parse(req.body);
LVDB::setLocalConfig(newConfig);
this->config = newConfig;
}catch(exception &e) {
json ret;
ret["code"] = 1;
ret["msg"] = e.what();
ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
res.set_content(ret.dump(), "text/json");
}
});
svr.Post("/reset", [](const Request& req, Response& res){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论