| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/server.R |
| 3 |
\name{handler_directory} |
| 4 |
\alias{handler_directory} |
| 5 |
\title{Create Static Directory Handler} |
| 6 |
\usage{ |
| 7 |
handler_directory(path, directory) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{path}{URI path prefix (e.g., "/static"). Requests to "/static/foo.js" |
| 11 |
will serve "directory/foo.js".} |
| 12 |
|
| 13 |
\item{directory}{Path to the directory to serve.} |
| 14 |
} |
| 15 |
\value{ |
| 16 |
A handler object for use with \code{\link[=http_server]{http_server()}}. |
| 17 |
} |
| 18 |
\description{ |
| 19 |
Creates an HTTP handler that serves files from a directory tree. NNG handles |
| 20 |
MIME type detection automatically. |
| 21 |
} |
| 22 |
\details{ |
| 23 |
Directory handlers automatically match all paths under the prefix (prefix |
| 24 |
matching is implicit). The URI path is mapped to the filesystem: |
| 25 |
\itemize{ |
| 26 |
\item Request to "/static/css/style.css" serves "directory/css/style.css" |
| 27 |
\item Request to "/static/" serves "directory/index.html" if it exists |
| 28 |
} |
| 29 |
|
| 30 |
Note: The trailing slash behavior depends on how clients make requests. |
| 31 |
A request to "/static" (no trailing slash) will not automatically redirect |
| 32 |
to "/static/". Consider using \code{\link[=handler_redirect]{handler_redirect()}} if you need this behavior. |
| 33 |
} |
| 34 |
\examples{ |
| 35 |
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf} |
| 36 |
h <- handler_directory("/static", "www/assets") |
| 37 |
\dontshow{\}) # examplesIf} |
| 38 |
} |