First server executable

This commit is contained in:
2026-06-22 13:20:10 +03:00
parent ea99e81dbf
commit 6ff7c8a6cb
8 changed files with 245 additions and 0 deletions

79
main.cpp Normal file
View File

@@ -0,0 +1,79 @@
#include <iostream>
#include <memory>
#include <string>
#include <stdint.h>
#include "httplib.h"
#include "json.hpp"
#include "helpers.h"
using nlohmann::json;
using namespace std;
int main(int argc, char **argv)
{
string config_filename = "config.json";
string devices_filename = "devices.json";
string host = "";
string cert_file = "";
string key_file = "";
uint16_t port = 0;
shared_ptr<httplib::Server> server = nullptr;
bool ok;
json cfg;
if (argc > 2)
{
config_filename = argv[1];
}
ok = read_config_json(cfg, config_filename, &cout);
if (!ok)
{
return -1;
}
json_extract(cfg, "devices_filename", devices_filename);
json_extract(cfg, "host", host);
json_extract(cfg, "port", port);
// json_extract(cfg, "cert_file", cert_file);
// json_extract(cfg, "key_file", cert_file);
if (host.empty())
{
cout << "host not provided" << endl;
return -1;
}
if (0 == port)
{
cout << "port number not provided" << endl;
return -1;
}
if (!cert_file.empty() && !key_file.empty())
{
// TODO: Implement SSL Server Properly
}
else
{
server = make_shared<httplib::Server>();
}
server->listen(host, port);
server->Get("/api/setup", [](const httplib::Request& req, httplib::Response& res)
{
cout << req.headers.size() << endl;
for (auto header : req.headers)
{
cout << header.first << ": " << header.second << endl;
}
res.status = 400;
});
return 0;
}