Skip to content

Commit 547bbf1

Browse files
authored
Add DUCKDB_HTTPSERVER_BASEPATH (quackscience#23)
Implements new ENV variable to control the API basepath: `DUCKDB_HTTPSERVER_BASEPATH=/custom`
1 parent a95d01a commit 547bbf1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/httpserver_extension.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,16 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
325325
global_state.is_running = true;
326326
global_state.auth_token = auth.GetString();
327327

328+
// Custom basepath, defaults to root /
329+
const char* base_path_env = std::getenv("DUCKDB_HTTPSERVER_BASEPATH");
330+
std::string base_path = "/";
331+
332+
if (base_path_env && base_path_env[0] == '/' && strlen(base_path_env) > 1) {
333+
base_path = std::string(base_path_env);
334+
}
335+
328336
// CORS Preflight
329-
global_state.server->Options("/",
337+
global_state.server->Options(base_path,
330338
[](const duckdb_httplib_openssl::Request& /*req*/, duckdb_httplib_openssl::Response& res) {
331339
res.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
332340
res.set_header("Content-Type", "text/html; charset=utf-8");
@@ -341,8 +349,8 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
341349
global_state.allocator = make_uniq<Allocator>();
342350

343351
// Handle GET and POST requests
344-
global_state.server->Get("/", HandleHttpRequest);
345-
global_state.server->Post("/", HandleHttpRequest);
352+
global_state.server->Get(base_path, HandleHttpRequest);
353+
global_state.server->Post(base_path, HandleHttpRequest);
346354

347355
// Health check endpoint
348356
global_state.server->Get("/ping", [](const duckdb_httplib_openssl::Request& req, duckdb_httplib_openssl::Response& res) {

0 commit comments

Comments
 (0)