Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ bool HttpServer::IsRunningOnMachine(ClientContext &context) {
}

const auto local_port = GetLocalPort(context);
auto local_url = StringUtil::Format("http://localhost:%d", local_port);
const auto local_host = GetLocalHost(context);
auto local_url = StringUtil::Format("http://%s:%d", local_host, local_port);

httplib::Client client(local_url);
return client.Get("/info");
Expand Down Expand Up @@ -94,19 +95,22 @@ const HttpServer &HttpServer::Start(ClientContext &context, bool *was_started) {

const auto remote_url = GetRemoteUrl(context);
const auto port = GetLocalPort(context);
const auto host = GetLocalHost(context);
auto server = GetInstance(context);
server->DoStart(port, remote_url);
server->DoStart(port, host, remote_url);
return *server;
}

void HttpServer::DoStart(const uint16_t _local_port,
const std::string &_local_host,
const std::string &_remote_url) {
if (Started()) {
throw std::runtime_error("HttpServer already started");
}

local_port = _local_port;
local_url = StringUtil::Format("http://localhost:%d", local_port);
local_host = _local_host;
local_url = StringUtil::Format("http://%s:%d", local_host, local_port);
remote_url = _remote_url;
user_agent =
StringUtil::Format("duckdb-ui/%s-%s(%s)", DuckDB::LibraryVersion(),
Expand Down Expand Up @@ -146,10 +150,11 @@ void HttpServer::DoStop() {
ddb_instance.reset();
remote_url = "";
local_port = 0;
local_host = "";
}

std::string HttpServer::LocalUrl() const {
return StringUtil::Format("http://localhost:%d/", local_port);
return StringUtil::Format("http://%s:%d/", local_host, local_port);
}

shared_ptr<DatabaseInstance> HttpServer::LockDatabaseInstance() {
Expand Down Expand Up @@ -185,7 +190,7 @@ void HttpServer::Run() {
const httplib::ContentReader &content_reader) {
HandleTokenize(req, res, content_reader);
});
server.listen("localhost", local_port);
server.listen(local_host, local_port);
}

void HttpServer::HandleGetInfo(const httplib::Request &req,
Expand Down
4 changes: 3 additions & 1 deletion src/include/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class HttpServer {
friend class Watcher;

// Lifecycle
void DoStart(const uint16_t local_port, const std::string &remote_url);
void DoStart(const uint16_t local_port, const std::string &local_host,
const std::string &remote_url);
void DoStop();
void Run();
void UpdateDatabaseInstance(shared_ptr<DatabaseInstance> context_db);
Expand Down Expand Up @@ -69,6 +70,7 @@ class HttpServer {
shared_ptr<DatabaseInstance> LockDatabaseInstance();

uint16_t local_port;
std::string local_host;
std::string local_url;
std::string remote_url;
weak_ptr<DatabaseInstance> ddb_instance;
Expand Down
3 changes: 3 additions & 0 deletions src/include/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#define UI_LOCAL_PORT_SETTING_NAME "ui_local_port"
#define UI_LOCAL_PORT_SETTING_DEFAULT 4213
#define UI_LOCAL_HOST_SETTING_NAME "ui_local_host"
#define UI_LOCAL_HOST_SETTING_DEFAULT "localhost"
#define UI_REMOTE_URL_SETTING_NAME "ui_remote_url"
#define UI_REMOTE_URL_SETTING_DEFAULT "https://ui.duckdb.org"
#define UI_POLLING_INTERVAL_SETTING_NAME "ui_polling_interval"
Expand All @@ -27,6 +29,7 @@ T GetSetting(const ClientContext &context, const char *setting_name) {

std::string GetRemoteUrl(const ClientContext &);
uint16_t GetLocalPort(const ClientContext &);
std::string GetLocalHost(const ClientContext &);
uint32_t GetPollingInterval(const ClientContext &);

} // namespace duckdb
4 changes: 4 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ uint16_t GetLocalPort(const ClientContext &context) {
return internal::GetSetting<uint16_t>(context, UI_LOCAL_PORT_SETTING_NAME);
}

std::string GetLocalHost(const ClientContext &context) {
return internal::GetSetting<std::string>(context, UI_LOCAL_HOST_SETTING_NAME);
}

uint32_t GetPollingInterval(const ClientContext &context) {
return internal::GetSetting<uint32_t>(context,
UI_POLLING_INTERVAL_SETTING_NAME);
Expand Down
8 changes: 8 additions & 0 deletions src/ui_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ static void LoadInternal(DatabaseInstance &instance) {
LogicalType::USMALLINT, Value::USMALLINT(default_port));
}

{
auto default_host = GetEnvOrDefault(UI_LOCAL_HOST_SETTING_NAME,
UI_LOCAL_HOST_SETTING_DEFAULT);
config.AddExtensionOption(UI_LOCAL_HOST_SETTING_NAME,
"Local host on which the UI server listens",
LogicalType::VARCHAR, Value(default_host));
}

{
auto def = GetEnvOrDefault(UI_REMOTE_URL_SETTING_NAME,
UI_REMOTE_URL_SETTING_DEFAULT);
Expand Down
Loading