Skip to content

Commit

Permalink
provide a way to bind webserver separately to specific ip
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Oct 12, 2023
1 parent 8908405 commit ee9fd49
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Server/Components/CustomModels/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class CustomModelsComponent final : public ICustomModelsComponent, public Player
bool enabled = true;
uint16_t modelsPort = 7777;
String modelsPath = "models";
String webServerBindAddress = "";
String cdn = "";
bool usingCdn = false;
uint16_t httpThreads = 50; // default max_players is 50
Expand Down Expand Up @@ -414,6 +415,7 @@ class CustomModelsComponent final : public ICustomModelsComponent, public Player
config.setString("artwork.models_path", modelsPath);
config.setInt("network.http_threads", httpThreads);
config.setInt("artwork.port", modelsPort);
config.setString("artwork.web_server_bind", webServerBindAddress);
}
else
{
Expand All @@ -440,6 +442,13 @@ class CustomModelsComponent final : public ICustomModelsComponent, public Player
{
config.setInt("artwork.port", modelsPort);
}
// We provide a way for users to set webserver bind address, sometimes they want it
// To be different rather than 127.0.0.1 or server's public IP. For example, in some
// Situations you want to bind it to 0.0.0.0, like in a docker container.
if (config.getType("artwork.web_server_bind") == ConfigOptionType_None)
{
config.setString("artwork.web_server_bind", webServerBindAddress);
}
}
}

Expand All @@ -453,6 +462,7 @@ class CustomModelsComponent final : public ICustomModelsComponent, public Player
modelsPath = String(core->getConfig().getString("artwork.models_path"));
cdn = String(core->getConfig().getString("artwork.cdn"));
httpThreads = *core->getConfig().getInt("network.http_threads");
webServerBindAddress = String(core->getConfig().getString("artwork.web_server_bind"));

NetCode::RPC::RequestTXD::addEventHandler(*core, &requestDownloadLinkHandler);
NetCode::RPC::RequestDFF::addEventHandler(*core, &requestDownloadLinkHandler);
Expand Down Expand Up @@ -521,7 +531,21 @@ class CustomModelsComponent final : public ICustomModelsComponent, public Player
return;
}

webServer = new WebServer(core, modelsPath, core->getConfig().getString("network.bind"), *core->getConfig().getInt("artwork.port"), core->getConfig().getString("network.public_addr"), httpThreads);
StringView bindAddress;
StringView networkBindAddress = core->getConfig().getString("network.bind");
if (webServerBindAddress.size())
{
bindAddress = StringView(webServerBindAddress.c_str(), webServerBindAddress.size());
}
else
{
if (!networkBindAddress.empty())
{
bindAddress = networkBindAddress;
}
}

webServer = new WebServer(core, modelsPath, bindAddress, *core->getConfig().getInt("artwork.port"), core->getConfig().getString("network.public_addr"), httpThreads);

if (webServer->is_running())
{
Expand Down

0 comments on commit ee9fd49

Please sign in to comment.