# Module yapp

- Description
- Data Types
- Function Index
- Function Details

Yaws applications handler.

Introduced in: 11 Dec 2005 by Mikael Karlsson <mikael@creado.se>

Authors: Mikael Karlsson (`mikael@creado.se`).

See also: yapp_handler.

## Description

Yaws applications handler.

An easy way to deploy Yaws applications independently of each other.

This module implements Yaws runmod and arg_rewrite_mod interfaces. It has functions to insert and remove Yapps to the Yaws sconfs records. It is used by the yapp_handler implementation. The yapp module will make Yaws temporarily switch the docroot to the applications priv/docroot directory when it encounters the registered URL path of the application. One can set another docroot than the default (priv/docroot) by setting the environment variable yapp_docroot in the .app file for the application. The application may also have own appmods which are put in the application environment variable yapp_appmods like:

`{env, [ {yapp_appmods,[{"ctrl",enityme_controller}]} ]},`

In order to include the yapp module, runmod shall be set to yapp. The arg_rewrite_mod shall also be set to yapp and the opaque variable yapp_server_id shall be set to an unique string for every virtual server using yapp, like:

       .
       ebin_dir = /usr/local/yaws/lib/yapp/ebin
       .
       runmod = yapp
       .
       <server aspen4>
              port = 8001
              listen = 0.0.0.0
              dir_listings = true
              arg_rewrite_mod = yapp
              docroot = /home/yaws/scripts/../www
              <opaque>
                      yapp_server_id = aspeninternal
                      bootstrap_yapps = yapp
              </opaque>
       </server>

Note: The yapp application is in itself a "Yapp" with a small admin console. So by adding the line `bootstrap_yapps = yapp` as above you will get access to the admin console on http://yourservername/yapp/index.html

Note2: The current available registry implementation uses Mnesia so you need to create a mnesia schema (if not already done) for the node(s) you are running Yaws on. `mnesia:create_schema([node()]).`

## Data Types

### yawsArg()

`yawsArg() = #arg{}`

The #arg record as defined by yaws_api.hrl.

### yawsSconf()

`yawsSconf() = #sconf{}`

The #sconf record as defined by yaws.hrl.

## Function Index

arg_rewrite/1 | Interface function for a Yaws arg_rewrite_mod.
get_bootstrap_yapps/0 | Gets the Yapps defined in each opaque "bootstrap_yapps = appname1, appname2" for every server id.
get_server_ids/0 | Lists all server ids.
get_yapps/0 | Gets all Yapps that are configured for the Yaws server.
log/3 | Yapp interface to the error_logger.
prepath/1 | Get the Yapp root-path.
reset_yaws_conf/0 |
srv_id/1 | Get the server id from an Sconf if available.
start/0 | Interface function for Yaws run_mod.

## Function Details

### arg_rewrite/1

`arg_rewrite(Arg::yawsArg()) -> yawsArg()`

Interface function for a Yaws arg_rewrite_mod. If it finds a registered Yapp it will strip of the path up to the Yapp and redirect the docroot.

### get_bootstrap_yapps/0

`get_bootstrap_yapps() -> [{ServerId, [{Path, ApplicationName}]}]`

- `ServerId = string()`
- `Path = string()`
- `ApplicationName = atom()`

Gets the Yapps defined in each opaque "bootstrap_yapps = appname1, appname2" for every server id. (If available). Bootstrap yapps will get the same pathname as their application name and are "static" meaning that they can not be removed from the server unless yaws.conf is changed (or if embedded yaws - yaws:setconf/2 is used).

### get_server_ids/0

`get_server_ids() -> [ServerId::string()]`

Lists all server ids.

### get_yapps/0

`get_yapps() -> [{ServerId, [{yapp, Urlpath, Docroot, Appname, Appmods}]}]`

- `ServerId = string()`
- `Urlpath = string()`
- `Docroot = string()`
- `Appname = atom()`
- `Appmods = [atom()]`

Gets all Yapps that are configured for the Yaws server.

### log/3

`log(Level, FormatStr::string(), Args::[term()]) -> ok`

- `Level = error | warning | info | debug`

Yapp interface to the error_logger.

### prepath/1

`prepath(Arg::yawsArg()) -> Path::string()`

Get the Yapp root-path. Can be called from a Yapp erl/1 fun or an erl section in a .yaws file to get the Yapp root path.

### reset_yaws_conf/0

`reset_yaws_conf() -> any()`

### srv_id/1

`srv_id(Sconf::yawsSconf()) -> string() | undefined`

Get the server id from an Sconf if available

### start/0

`start() -> ok | {error, Reason::term()}`

Interface function for Yaws run_mod. This fun is spawned from Yaws so no return val is expected. All Yapps can expect mnesia to be started, so mnesia is ensured to be started. For every server id that has Yapps the yapp module is registered as an arg_rewrite_mod in #sconf. Configuration data for mapping Yapp paths to applications is looked up in a mnesia registry table and stored in Yaws #sconf.opaque record for the each server id.

Generated by EDoc