Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually use apiPath when mounting the docs #977

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this still needs to be there as the docs will want to be mounted again on a followup run.

}

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
Loading