Skip to content
Merged
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
14 changes: 11 additions & 3 deletions src/httpserver_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,16 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
global_state.is_running = true;
global_state.auth_token = auth.GetString();

// Custom basepath, defaults to root /
const char* base_path_env = std::getenv("DUCKDB_HTTPSERVER_BASEPATH");
std::string base_path = "/";

if (base_path_env && base_path_env[0] == '/' && strlen(base_path_env) > 1) {
base_path = std::string(base_path_env);
}

// CORS Preflight
global_state.server->Options("/",
global_state.server->Options(base_path,
[](const duckdb_httplib_openssl::Request& /*req*/, duckdb_httplib_openssl::Response& res) {
res.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
res.set_header("Content-Type", "text/html; charset=utf-8");
Expand All @@ -341,8 +349,8 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
global_state.allocator = make_uniq<Allocator>();

// Handle GET and POST requests
global_state.server->Get("/", HandleHttpRequest);
global_state.server->Post("/", HandleHttpRequest);
global_state.server->Get(base_path, HandleHttpRequest);
global_state.server->Post(base_path, HandleHttpRequest);

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