Covalent Bond  0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
liveThread.cpp
Go to the documentation of this file.
1 
11 #include "liveThread.hpp"
12 #include <workflow/WFHttpServer.h>
13 
15  // start execute the website.
16  std::ifstream fp("./index.html");
17  std::string __htmlIndexBody((std::istreambuf_iterator<char>(fp)),
18  std::istreambuf_iterator<char>());
19  fp.close();
20  fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) | fmt::emphasis::underline,
21  "--- OS info ---\n");
22  fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic, "{}\n", m_sysInfo.m_osInfo);
23  fmt::print("[ info ] Get the ./index.html file. Start HTTP server at {}{}\n",
24  "http://localhost:", m_httpServerPort);
25  fmt::print("[ info ] Press ^C to stop server.\n");
26 
27  WFHttpServer server([=](WFHttpTask* task) {
28  protocol::HttpResponse* resp = task->get_resp();
29  resp->add_header_pair("Content-Type", "text/html; charset=utf-8");
30  resp->set_http_version("HTTP/1.1");
31  resp->set_status_code("200");
32  resp->set_reason_phrase("OK");
33  resp->append_output_body(__htmlIndexBody.c_str());
34  });
35  // Fork a daemon thread here and do other things.
36  // And in the scope below, need to reduce the thread forked.
37  if (server.start(m_httpServerPort) == 0) {
38  pause();
39  server.stop();
40  }
41 }
frontThread::m_sysInfo
cb::utils::sysInfo m_sysInfo
Definition: liveThread.hpp:40
liveThread.hpp
frontThread::m_httpServerPort
unsigned short m_httpServerPort
Definition: liveThread.hpp:39
frontThread::exec
virtual void exec()
Definition: liveThread.cpp:14
cb::utils::sysInfo::m_osInfo
char m_osInfo[__DESCRIBE_CHAR_MAX_NUMS_DOUBLE]
Definition: sysStatus.hpp:39