R: Class 'Brewery'

Brewery-class {Rook} | R Documentation

## Class `Brewery`

### Description

A `Middleware` class for mapping URLs to a directory of files that are subsequently passed to `brew`. When a file is brewed, the two variables `req` (an object of class `Request`) and `res` (an object of class `Response`) are available for use.

### Methods

`new(url,root,...):`

  `url` is a character string or `regexp` on which to match, `root` is the name of the directory where brew files reside. Named arguments can be passed in via `...` and will be available within the scope of each brewed file.

### See Also

`Rhttpd`, `Builder`, `Redirect`, and `brew`.

### Examples

    #
    # This application runs any file found in tempdir() through brew.
    #
    s <- Rhttpd$new()
    ## Not run:
    s$start(quiet=TRUE)

    ## End(Not run)
    cat("<h1>Random Number: <%=rnorm(1)%></h1>",
        file=file.path(tempdir(),"index.html"))
    s$add(name="random",
        app=Builder$new(
            Brewery$new(url="/",root=tempdir()),
            Redirect$new("/index.html")
        )
    )
    ## Not run:
    s$browse('random') # Opens a browser window to the app.

    ## End(Not run)
    file.remove(file.path(tempdir(),"index.html"))
    s$remove(all=TRUE)
    rm(s)

[Package Rook version 1.1-1 Index]