rrserverestrserve

Cannot deveolop API using RestRserve on remote server


Condider that I've built my application as in te example below:

library(RestRserve)
app = Application$new()
app$add_get(
  path = "/hello", 
  FUN = function(request, response) {
    response$set_body("Hello from RestRserve")
  })
backend = BackendRserve$new()
backend$start(app, http_port = 8080)

With the last command, Rserve wakes up and correctly listens and answers to the request on port 8080. Now, I would like to put the commands above in a script on a remote server, launch it with Rscript, and make it listen forever. However, once I disconnect from ssh, it stops working. Am I doing something wrong? Notice that I installed only RestRserve, Rserve come as a dependency, but I did not change anything or customized any configuration file.


Solution

  • I solved with the help of rexy.ai and karo: The correct script uses backend$start(app, http_port = 8080) (with no background option) but the deployment is made using nohup Rscript app.R &. This let the app run remotely and accept requests!