Skip to content

Commit

Permalink
Actually use apiPath when mounting the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Jan 24, 2025
1 parent f4230ed commit 5980d1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions R/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 5980d1e

Please sign in to comment.