Skip to content

Commit 1f24363

Browse files
committed
SSL support.
1 parent 46e0fe9 commit 1f24363

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

main.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <drogon/drogon.h>
33
#include <fmt/format.h>
44
#include <boost/program_options.hpp>
5+
#include <spdlog/spdlog.h>
56

67

78
using namespace drogon;
@@ -116,6 +117,7 @@ namespace po = boost::program_options;
116117
int main( int argc, char** argv )
117118
{
118119
std::string host;
120+
std::filesystem::path certPath, keyPath;
119121
int port;
120122

121123
po::options_description desc( "Simple Inference Server" );
@@ -124,6 +126,8 @@ int main( int argc, char** argv )
124126
( "invokePath", po::value( &globalConfig.invokePath )->required(), "Path to the script that will be invoked" )
125127
( "host", po::value( &host )->default_value( "127.0.0.1" ), "Host to bind to" )
126128
( "port", po::value( &port )->default_value( 7654 ), "Port to bind to" )
129+
( "cert", po::value( &certPath )->default_value( {} ), "Path to SSL certificate" )
130+
( "key", po::value( &keyPath )->default_value( {} ), "Path to SSL key" )
127131
;
128132

129133
po::variables_map vm;
@@ -147,9 +151,24 @@ int main( int argc, char** argv )
147151
app().registerHandler( "/track_result", std::function{ trackResultHandler } );
148152
app().registerHandler( "/get_result", std::function{ getResultHandler } );
149153
app().registerHandler( "/", std::function{ submitTask }, { Post } );
154+
155+
const bool useSSL = exists( certPath ) && exists( keyPath );
156+
if ( useSSL && !app().supportSSL() )
157+
{
158+
spdlog::error( "Current configuration does not support SSL" );
159+
return -1;
160+
}
161+
162+
if ( useSSL )
163+
spdlog::info( "Use SSL" );
164+
else
165+
spdlog::info( "Do not use SSL" );
166+
167+
spdlog::default_logger()->flush();
168+
150169
app()
151170
.setClientMaxBodySize( 1024*1024*1024 ) // 1gb
152-
.addListener( host, port )
171+
.addListener( host, port, useSSL, certPath, keyPath )
153172
.run();
154173

155174
return 0;

0 commit comments

Comments
 (0)