diff --git a/R/shiny.R b/R/shiny.R index a7cce4ea0a..50ac94bd2c 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -2126,6 +2126,51 @@ ShinySession <- R6Class( } }) } + }, + + getUrl = function() { + req <- self$request + + url <- + # Connect + req[["HTTP_X_RSC_REQUEST"]] %||% + req[["HTTP_RSTUDIO_CONNECT_APP_BASE_URL"]] %||% + # ShinyApps.io + if (!is.null(req[["HTTP_X_REDX_FRONTEND_NAME"]])) { + paste0("https://", req[["HTTP_X_REDX_FRONTEND_NAME"]]) + } + + if (is.null(url)) { + forwarded_host <- req[["HTTP_X_FORWARDED_HOST"]] + forwarded_port <- req[["HTTP_X_FORWARDED_PORT"]] + + host <- if (!is.null(forwarded_host) && !is.null(forwarded_port)) { + paste0(forwarded_host, ":", forwarded_port) + } else { + req[["HTTP_HOST"]] %||% paste0(req[["SERVER_NAME"]], ":", req[["SERVER_PORT"]]) + } + + proto <- req[["HTTP_X_FORWARDED_PROTO"]] %||% req[["rook.url_scheme"]] + + if (tolower(proto) == "http") { + host <- sub(":80$", "", host) + } else if (tolower(proto) == "https") { + host <- sub(":443$", "", host) + } + + url <- paste0( + proto, + "://", + host, + req[["SCRIPT_NAME"]], + req[["PATH_INFO"]] + ) + } + + # Strip existing querystring, if any + url <- sub("\\?.*", "", url) + + url } ) ) diff --git a/man/runApp.Rd b/man/runApp.Rd index 9daf245caf..ce4ff37a61 100644 --- a/man/runApp.Rd +++ b/man/runApp.Rd @@ -30,7 +30,10 @@ expression that produces a Shiny app object. \item{port}{The TCP port that the application should listen on. If the \code{port} is not specified, and the \code{shiny.port} option is set (with \code{options(shiny.port = XX)}), then that port will be used. Otherwise, -use a random port.} +use a random port between 3000:8000, excluding ports that are blocked +by Google Chrome for being considered unsafe: 3659, 4045, 5060, +5061, 6000, 6566, 6665:6669 and 6697. Up to twenty random +ports will be tried.} \item{launch.browser}{If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in diff --git a/man/runExample.Rd b/man/runExample.Rd index 89cc9969f9..c17a40ba56 100644 --- a/man/runExample.Rd +++ b/man/runExample.Rd @@ -19,7 +19,10 @@ list the available examples.} \item{port}{The TCP port that the application should listen on. If the \code{port} is not specified, and the \code{shiny.port} option is set (with \code{options(shiny.port = XX)}), then that port will be used. Otherwise, -use a random port.} +use a random port between 3000:8000, excluding ports that are blocked +by Google Chrome for being considered unsafe: 3659, 4045, 5060, +5061, 6000, 6566, 6665:6669 and 6697. Up to twenty random +ports will be tried.} \item{launch.browser}{If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in