Added basic diplay endpoint. Added images folder.
This commit is contained in:
32
main.cpp
32
main.cpp
@@ -48,6 +48,7 @@ int main(int argc, char **argv)
|
||||
json_extract(cfg, "devices_filename", devices_filename);
|
||||
json_extract(cfg, "host", host);
|
||||
json_extract(cfg, "port", port);
|
||||
json_extract(cfg, "folder_images", folder_images);
|
||||
// json_extract(cfg, "cert_file", cert_file);
|
||||
// json_extract(cfg, "key_file", cert_file);
|
||||
|
||||
@@ -63,6 +64,12 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (folder_images.empty())
|
||||
{
|
||||
cout << "folder for images is empty" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!cert_file.empty() && !key_file.empty())
|
||||
{
|
||||
// TODO: Implement SSL Server Properly
|
||||
@@ -151,6 +158,16 @@ int main(int argc, char **argv)
|
||||
}
|
||||
};
|
||||
|
||||
auto display_handler = [&container, &devices_filename](const httplib::Request& req, httplib::Response& res)
|
||||
{
|
||||
res.status = 500;
|
||||
|
||||
for (auto header : res.headers)
|
||||
{
|
||||
cout << header.first << ": " << header.second << endl;
|
||||
}
|
||||
};
|
||||
|
||||
auto log_handler = [](const httplib::Request& req, httplib::Response& res)
|
||||
{
|
||||
try
|
||||
@@ -165,12 +182,19 @@ int main(int argc, char **argv)
|
||||
res.status = 200;
|
||||
};
|
||||
|
||||
server->Get("/api/setup/", setup_handler);
|
||||
server->Get("/api/setup", setup_handler);
|
||||
|
||||
server->Post("/api/log/", log_handler);
|
||||
server->Post("/api/log", log_handler);
|
||||
server->Get("/api/setup/*", setup_handler);
|
||||
server->Get("/api/display/*", display_handler);
|
||||
server->Post("/api/log/*", log_handler);
|
||||
|
||||
ok = server->set_mount_point("/images", folder_images);
|
||||
if (!ok)
|
||||
{
|
||||
cout << "Could not mount images folder" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << "Server listening on " << host << ":" << port << endl;
|
||||
server->listen(host, port);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user