% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/app.R
\name{new_app}
\alias{new_app}
\alias{stop_app}
\title{Create or stop a local web application}
\usage{
new_app(name, handler, open = interactive(), host = "127.0.0.1", port = NULL)

stop_app(name = names(.proxy$apps))
}
\arguments{
\item{name}{App name (a character string). Use \code{name = ''} to serve the app
at the root URL \verb{http://host:PORT/} via the proxy. If \code{name} is non-empty,
the app is served directly by R's internal httpd at \verb{/custom/name/}. Each
name must be unique; calling \code{new_app()} with an existing name replaces
that app. For \code{stop_app()}, a character vector of app names to stop;
defaults to all running apps.}

\item{handler}{A function with signature \verb{function(path, query, post, headers)} that handles HTTP requests and returns a response list.}

\item{open}{Whether to open the app URL in a browser, or a function to open
it. In non-interactive sessions this also controls whether the call
blocks: passing \code{open = FALSE} explicitly suppresses both browser-opening
and blocking.}

\item{host}{Bind address for the proxy (\code{"127.0.0.1"} or \code{"0.0.0.0"}). Only
used when \code{name = ''}.}

\item{port}{Candidate proxy ports when \code{name = ''}. The first available port
is selected (falling back to \code{\link[=random_port]{random_port()}} if needed). Ignored when
\code{name != ''}.}
}
\value{
\code{new_app()} returns the app URL invisibly. \code{stop_app()} returns
nothing.
}
\description{
Create a local web application based on R's internal httpd.
}
\details{
\code{new_app()} has two modes:
\itemize{
\item \code{name = ''}: start an app behind a lightweight proxy at
\verb{http://host:PORT/}, forwarding to R's internal httpd path
\verb{/custom/xfun:PORT/}.
\item \code{name != ''}: register a legacy app directly on R's internal httpd at
\verb{http://127.0.0.1:BACKEND/custom/name/} (compatible with older versions).
}

\code{stop_app()} deregisters one or more running apps.
}
