[QUESTION] Working with environment variables
Hi, I was wondering if you could provide some support on this situation: I'm new to RestRserve (I have only worked with Plumber), my development os is windows and my pre-production os is linux. I created a simple function that returns the branch, therefore, the code uses environment variables.
Here's the code:
library(RestRserve)
print('-- Create Application --')
app = Application$new(
# content_type = 'application/json'
)
app$add_post(
path = "/whatbranch",
FUN = function(.req, .res) {
print(".req$body:")
print(.req$body)
print(paste('-- YOU ARE IN:',Sys.getenv('ENTORNO'),'--'))
.res$set_content_type("application/json")
.res$set_body(Sys.getenv('ENTORNO'))
}
)
backend = BackendRserve$new()
backend$start(app, http_port = 8001)
When I test this function on Postman, the output is as expected:
However, when putting this code in production, the ouput is black:
(the response)
(the code prints)
The r environ file has all the necessary environment variables in all branches.
Also, I noticed that, is it's mandatory for me to "declare" (in production) my main .LibPath at the top of the script ( .libPaths("/home/romina/R/x86_64-pc-linux-gnu-library/4.3")) , otherwise, the libraries can't be installed.
On this page some guidelines for deploying are shown, for example, for setting the port of the app they use:
configuration = c("http.port" = "8001",
"encoding" = "utf8",
"port" = "6311")
So I was wondering if I could add the environment variables in this vector.
Thanks in advance, I'm really looking forward to use this library.