5151#error "Unsupported platform!"
5252#endif
5353
54- void RunServer (std::optional<int > port, bool ignore_cout) {
54+ void RunServer (std::optional<std::string> host, std::optional<int > port,
55+ bool ignore_cout) {
5556#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
5657 signal (SIGINT, SIG_IGN);
5758#elif defined(_WIN32)
@@ -62,16 +63,24 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
6263 reinterpret_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
6364#endif
6465 auto config = file_manager_utils::GetCortexConfig ();
65- if (port.has_value () && *port != std::stoi (config.apiServerPort )) {
66+ if (host.has_value () || port.has_value ()) {
67+ if (host.has_value () && *host != config.apiServerHost ) {
68+ config.apiServerHost = *host;
69+ }
70+
71+ if (port.has_value () && *port != std::stoi (config.apiServerPort )) {
72+ config.apiServerPort = std::to_string (*port);
73+ }
74+
6675 auto config_path = file_manager_utils::GetConfigurationPath ();
67- config.apiServerPort = std::to_string (*port);
6876 auto result =
6977 config_yaml_utils::CortexConfigMgr::GetInstance ().DumpYamlConfig (
7078 config, config_path.string ());
7179 if (result.has_error ()) {
7280 CTL_ERR (" Error update " << config_path.string () << result.error ());
7381 }
7482 }
83+
7584 if (!ignore_cout) {
7685 std::cout << " Host: " << config.apiServerHost
7786 << " Port: " << config.apiServerPort << " \n " ;
@@ -283,6 +292,7 @@ int main(int argc, char* argv[]) {
283292 // avoid printing logs to terminal
284293 is_server = true ;
285294
295+ std::optional<std::string> server_host;
286296 std::optional<int > server_port;
287297 bool ignore_cout_log = false ;
288298#if defined(_WIN32)
@@ -296,6 +306,8 @@ int main(int argc, char* argv[]) {
296306 std::wstring v = argv[i + 1 ];
297307 file_manager_utils::cortex_data_folder_path =
298308 cortex::wc::WstringToUtf8 (v);
309+ } else if (command == L" --host" ) {
310+ server_host = cortex::wc::WstringToUtf8 (argv[i + 1 ]);
299311 } else if (command == L" --port" ) {
300312 server_port = std::stoi (argv[i + 1 ]);
301313 } else if (command == L" --ignore_cout" ) {
@@ -312,6 +324,8 @@ int main(int argc, char* argv[]) {
312324 file_manager_utils::cortex_config_file_path = argv[i + 1 ];
313325 } else if (strcmp (argv[i], " --data_folder_path" ) == 0 ) {
314326 file_manager_utils::cortex_data_folder_path = argv[i + 1 ];
327+ } else if (strcmp (argv[i], " --host" ) == 0 ) {
328+ server_host = argv[i + 1 ];
315329 } else if (strcmp (argv[i], " --port" ) == 0 ) {
316330 server_port = std::stoi (argv[i + 1 ]);
317331 } else if (strcmp (argv[i], " --ignore_cout" ) == 0 ) {
@@ -367,6 +381,6 @@ int main(int argc, char* argv[]) {
367381 }
368382 }
369383
370- RunServer (server_port, ignore_cout_log);
384+ RunServer (server_host, server_port, ignore_cout_log);
371385 return 0 ;
372386}
0 commit comments