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

Swagger UI returns 404 error with pm2 #173

Closed
jeffkeller87 opened this issue Sep 26, 2017 · 6 comments
Closed

Swagger UI returns 404 error with pm2 #173

jeffkeller87 opened this issue Sep 26, 2017 · 6 comments

Comments

@jeffkeller87
Copy link

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 :(

@trestletech
Copy link
Contributor

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

@jeffkeller87
Copy link
Author

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

@jeffkeller87
Copy link
Author

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

@david-waterworth
Copy link

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

@trestletech
Copy link
Contributor

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).

@jeffkeller87
Copy link
Author

jeffkeller87 commented Oct 19, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants