// Copyright Epic Games, Inc. All Rights Reserved. #include "httpuws.h" #pragma warning(push) #pragma warning(disable : 4244 4324 4267 4458 4706) #include #pragma warning(pop) #include #include #if ZEN_PLATFORM_WINDOWS # pragma comment(lib, "Iphlpapi.lib") #endif namespace zen { HttpUwsServer::HttpUwsServer() { } HttpUwsServer::~HttpUwsServer() { } void HttpUwsServer::RegisterService(HttpService& Service) { ZEN_UNUSED(Service); } void HttpUwsServer::Initialize(int BasePort) { m_BasePort = BasePort; } void HttpUwsServer::Run(bool TestMode) { if (TestMode == false) { zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Press ESC or Q to quit"); } ::uWS::App() .get("/*", [](uWS::HttpResponse* res, uWS::HttpRequest* req) { res->end("Hello world!"); ZEN_UNUSED(req); }) .post("/*", [](uWS::HttpResponse* res, uWS::HttpRequest* req) { res->onData([&](std::string_view Data, bool fin) { ZEN_UNUSED(Data); if (fin) res->end("Hello world!"); }); res->onAborted([&] {}); ZEN_UNUSED(req); }) .listen(m_BasePort, [](auto* listen_socket) { ZEN_UNUSED(listen_socket); }) .run(); do { int WaitTimeout = -1; if (!TestMode) { WaitTimeout = 1000; } if (!TestMode && _kbhit() != 0) { char c = (char)_getch(); if (c == 27 || c == 'Q' || c == 'q') { RequestApplicationExit(0); } } m_ShutdownEvent.Wait(WaitTimeout); } while (!IsApplicationExitRequested()); } void HttpUwsServer::RequestExit() { m_ShutdownEvent.Set(); } } // namespace zen