#include #include #include namespace App { constexpr auto DefaultPort = 8888; constexpr auto DefaultHost = "0.0.0.0"; static httplib::Server *srv = nullptr; } void signalHandler(int signum) { std::cout << "\n\nInterrupt signal (" << signum << ") received.\n"; if (App::srv) { App::srv->stop(); delete App::srv; } exit(signum); } int main(int argc, char *argv[]) { std::signal(SIGINT, signalHandler); App::srv = new httplib::Server(); App::srv->Get("/", [](const httplib::Request &, httplib::Response &res) { noolitelib::Noolite adapter; if (adapter.sendCommand(0, noolitelib::Switch)) { res.set_content("{\"Result\":\"Successful\"}", "application/json"); } else { res.set_content("{\"Result\":\"Failed\"}", "application/json"); } }); auto host = App::DefaultHost; auto port = App::DefaultPort; if (argc > 1) { host = argv[1]; } if (argc > 2) { port = atoi(argv[2]); } App::srv->listen(host, port); return 0; }