IXWebSocket/ws/ws_httpd.cpp

44 lines
975 B
C++
Raw Normal View History

/*
* ws_httpd.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
*/
#include <fstream>
#include <ixwebsocket/IXHttpServer.h>
#include <spdlog/spdlog.h>
2019-09-23 19:25:23 +02:00
#include <sstream>
#include <vector>
namespace ix
{
2019-10-01 02:52:39 +02:00
int ws_httpd_main(int port,
const std::string& hostname,
bool redirect,
const std::string& redirectUrl,
const ix::SocketTLSOptions& tlsOptions)
{
spdlog::info("Listening on {}:{}", hostname, port);
ix::HttpServer server(port, hostname);
server.setTLSOptions(tlsOptions);
if (redirect)
{
2019-09-26 18:45:59 +02:00
server.makeRedirectServer(redirectUrl);
}
auto res = server.listen();
if (!res.first)
{
spdlog::error(res.second);
return 1;
}
server.start();
server.wait();
return 0;
}
2019-09-23 19:25:23 +02:00
} // namespace ix