From 5980d1e2ebab3a63c058813931cd0e16e6690e16 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Fri, 24 Jan 2025 14:41:05 +0100 Subject: [PATCH] Actually use apiPath when mounting the docs --- NEWS.md | 1 + R/plumber.R | 3 +-- R/ui.R | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 407d8316..53badd4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * Added support for graphic devices provided by ragg and svglite (@thomasp85 #964) * `parse_rds()`, `parse_feather()`, and `parse_parquet()` no longer writes data to disk during parsing (@thomasp85, #942) +* Fixed a bug where setting the `apiPath` option wouldn't be honored when running the app (@thomasp85, #836) # plumber 1.2.2 diff --git a/R/plumber.R b/R/plumber.R index 0cad0ec6..acc4977c 100644 --- a/R/plumber.R +++ b/R/plumber.R @@ -254,7 +254,6 @@ Plumber <- R6Class( old_wd <- setwd(dirname(private$filename)) on.exit({setwd(old_wd)}, add = TRUE) } - if (isTRUE(docs_info$enabled)) { mount_docs( pr = self, @@ -264,7 +263,7 @@ Plumber <- R6Class( callback = swaggerCallback, quiet = quiet ) - on.exit(unmount_docs(self, docs_info), add = TRUE) + #on.exit(unmount_docs(self, docs_info), add = TRUE) } on.exit(private$runHooks("exit"), add = TRUE) diff --git a/R/ui.R b/R/ui.R index 18e6c2b9..cc9b5609 100644 --- a/R/ui.R +++ b/R/ui.R @@ -117,7 +117,8 @@ mount_openapi <- function(pr, api_url) { break } } - pr$handle("GET", "/openapi.json", openapi_fun, serializer = serializer_unboxed_json()) + path <- get_option_or_env("plumber.apiPath", "") + pr$handle("GET", paste0(path, "/openapi.json"), openapi_fun, serializer = serializer_unboxed_json()) invisible() } @@ -184,7 +185,7 @@ register_docs <- function(name, index, static = NULL) { stopifnot(is.function(index)) if (!is.null(static)) stopifnot(is.function(static)) - docs_root <- paste0("/__docs__/") + docs_root <- "/__docs__/" docs_paths <- c("/index.html", "/") mount_docs_func <- function(pr, api_url, ...) { # Save initial extra argument values @@ -210,8 +211,11 @@ register_docs <- function(name, index, static = NULL) { message("Overwritting existing `", docs_root, "` mount") message("") } - - pr$mount(docs_root, docs_router) + + pr$mount( + paste0(get_option_or_env("plumber.apiPath", ""), docs_root), + docs_router + ) # add legacy swagger redirects (RStudio Connect) redirect_info <- swagger_redirects()