-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
61 lines (53 loc) · 1.81 KB
/
main.cc
File metadata and controls
61 lines (53 loc) · 1.81 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <drogon/drogon.h>
#include "LDClient.h"
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <boost/algorithm/string.hpp>
using namespace drogon;
int main(int argc, char *argv[])
{
std::filesystem::path file_path{".env"};
if (std::filesystem::exists(file_path)) {
std::ifstream file(file_path);
if (!file.is_open()) {
std::cerr << "Error: Unable to open file " << file_path << std::endl;
return 1;
}
std::string line;
while (std::getline(file, line)) {
boost::trim(line);
if (line.empty()) {
continue;
}
if (line.find("#") == 0) {
continue;
}
if (line.find('=') > 0) {
std::string key = line.substr(0, line.find('='));
std::string value = line.substr(line.find('=') + 1);
if (setenv(key.c_str(), value.c_str(), 1) != 0) {
std::cerr << "Error: Unable to set an environment variable from the .env file." << std::endl;
return 1;
}
}
}
file.close();
} else {
std::cout << "Error: The .env file does not exist." << std::endl;
return 1;
}
std::ofstream MyFile("./static/js/keys.js");
MyFile << "const clientKey = \"" << std::getenv("LD_CLIENT_KEY") << "\";";
MyFile.close();
LDClient *ldclient = LDClient::getInstance();
app().addListener("0.0.0.0", 3000);
// Use executable directory as document root (static/ is copied there by CMake)
std::string exeDir = std::filesystem::path(argv[0]).parent_path().string();
app().setDocumentRoot(exeDir.empty() ? "./" : exeDir + "/");
app().run();
return 0;
}