R plumber api deployment on digital ocean with swagger

Viewed 1036

I am using plumber to deploy an R api to digital ocean. It's hard to provide a reproducible example here but what I want is for the swagger endpoint to compile and be available. It works locally but not on the digital ocean server.

Locally I do this:

library(plumber)
r <- plumb("api/plumber.R")
r$run(port=8000)

now the swagger docs are available at: http://127.0.0.1:8000/__swagger__/

When I deploy to the server as follows:

library(analogsea)
library(plumber)
my_droplet <- as.droplet("my_droplet")

do_deploy_api(
  droplet = my_droplet,
  path = "my_path",
  localPath = "my_local_path",
  port = 8000
)

do_forward(my_droplet, "my_path")

Now I go to [my_remote_ip]/my_path/__swagger__/ I get a 404.

Anyone know how to do this? Much appreciated.

1 Answers

I found a work around thanks to the conversation here. After do_deploy_api() and do_forward() i then do this:

droplet_execute([my_droplet], {
  system("sed -i 's/pr$run(port=8000)/pr$run(port=8000, swagger = TRUE)/g' /etc/systemd/system/plumber-[my_api].service", intern = TRUE) 
  system("systemctl daemon-reload", intern = TRUE)
  system("service plumber-[my_api] restart", intern = TRUE)
})
Related