Plumber: Swagger UI returns 404 error with pm2

Created on 26 Sep 2017  路  6Comments  路  Source: rstudio/plumber

I am hosting an API with pm2 on AWS but the Swagger UI page (http://hostname:port/__swagger_/) returns a 404 error. The Swagger UI shows up just fine when run locally with r$run(). Is this a limitation of pm2 hosting? Section 9.4 of the plumber documentation is unfortunately incomplete so I didn't get far very in trying to figure this out :(

Most helpful comment

Try r$run(port = 8000, host = "0.0.0.0", swagger=TRUE)

I had a similar issue with my service working in Rstudio but not in docker. I looked through the code and the default for swagger is swagger=interactive() so the swagger endpoint is only created if you explicitly request it except when running from an interactive session

Regards
Dave

All 6 comments

Single underscore on the end? I believe it should be /__swagger__/ (two underscores on either side)

Unfortunately, that was just a typo here on GitHub. http://hostname:port/__swagger__/ also throws a 404 error.

To clarify, running the contents of plumb.R interactively in RStudio Server on the AWS EC2 instance works. Here's the set up using the base example:

# myfile.R

#* @get /mean
normalMean <- function(samples=10){
  data <- rnorm(samples)
  mean(data)
}

#* @post /sum
addTwo <- function(a, b){
  as.numeric(a) + as.numeric(b)
}
# plumb.R
library(plumber)
r <- plumb("myfile.R")  # Where 'myfile.R' is the location of the file shown above
r$run(port = 8000, host = "0.0.0.0")

pm2 service (no swagger @ http://hostname:port/__swagger__/)

pm2 start --interpreter="Rscript" plumb.R

Try r$run(port = 8000, host = "0.0.0.0", swagger=TRUE)

I had a similar issue with my service working in Rstudio but not in docker. I looked through the code and the default for swagger is swagger=interactive() so the swagger endpoint is only created if you explicitly request it except when running from an interactive session

Regards
Dave

Oh, great point @WaterworthD . You'll want to set swagger=TRUE if you want the swagger interface to be available in your production environment. (The motivation here is that we don't want anyone to be surprised by the fact that they just leaked all their endpoints with documentation to their clients).

Thanks @WaterworthD, That did it! @trestletech are there plans to flesh out the swagger documentation (https://www.rplumber.io/docs/tips-tricks.html#swagger)?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

utkarshsaraf19 picture utkarshsaraf19  路  3Comments

EDiLD picture EDiLD  路  4Comments

cbuchacher picture cbuchacher  路  4Comments

meztez picture meztez  路  4Comments

Amalabdu picture Amalabdu  路  6Comments