-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (28 loc) · 961 Bytes
/
Copy pathmain.cpp
File metadata and controls
35 lines (28 loc) · 961 Bytes
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
#include "httplib.h"
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
static std::string read_file(const std::string& path) {
std::ifstream file(path);
std::stringstream ss;
ss << file.rdbuf();
return ss.str();
}
int main() {
httplib::Server svr;
const std::string landing = read_file("index.html");
svr.Get("/", [&](const httplib::Request&, httplib::Response& res) {
res.set_content(landing, "text/html; charset=utf-8");
});
svr.Get("/health", [](const httplib::Request&, httplib::Response& res) {
res.set_content(
R"({"message":"If you see this, your app is running well!"})",
"application/json");
});
const char* port_env = std::getenv("app_port");
int port = port_env && *port_env ? std::atoi(port_env) : 8080;
std::cout << "C++ sample listening on 0.0.0.0:" << port << std::endl;
svr.listen("0.0.0.0", port);
return 0;
}