new_app_process: Run a presser app in another process

Description Usage Arguments Value Examples

View source: R/app-process.R

Description

Runs an app in a subprocess, using callr::r_session.

Usage

1
2
3
4
5
6
7
new_app_process(
  app,
  port = NULL,
  opts = server_opts(remote = TRUE),
  process_timeout = 5000,
  callr_opts = NULL
)

Arguments

app

presser_app object, the web app to run.

port

Port to use. By default the OS assigns a port.

opts

Server options. See server_opts() for the defaults.

process_timeout

How long to wait for the subprocess to start, in milliseconds.

callr_opts

Options to pass to callr::r_session_options() when setting up the subprocess.

Value

A presser_app_process object.

Methods

The presser_app_process class has the following methods:

get_app()
get_port()
stop()
get_state()
local_env(envvars)
url(path = "/", query = NULL)

get_app() returns the app object.

get_port() returns the port the web server is running on.

stop() stops the web server, and also the subprocess. If the error log file is not empty, then it dumps its contents to the screen.

get_state() returns a string, the state of the web server:

local_env() sets the given environment variables for the duration of the app process. It resets them in $stop().

url() returns the URL of the web app. You can use the path parameter to return a specific path.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
app <- new_app()
app$get("/foo", function(req, res) {
  res$send("Hello world!")
})

proc <- new_app_process(app)
url <- proc$url("/foo")
resp <- curl::curl_fetch_memory(url)
cat(rawToChar(resp$content))

proc$stop()

presser documentation built on July 1, 2020, 5:49 p.m.