Appmods are a way to let the application programmer take control over the URL path. Or put in another way, to let the application programmer fake real paths in URLs where in reality an Erlang module is executing. Possibly an example will make this easy to understand. Say we have the following URL
http://www.example.org/pathelem/foo/bar/x.pdf
With the above URL, the webserver would try to deliver the file "/pathelem/foo/bar/x.pdf" relative to the docroot. However if we had specified "pathelem" as an appmod, the server would stop processing the URL after seeing the "pathelem" part of the URL. Say we had the following in our yaws.conf configuration file
<server tita> port = 8001 listen = 0.0.0.0 docroot = /home/klacke/yaws/yaws/scripts/../www appmods = <pathelem, myappmod> </server>
Then the webserver would invoke myappmod:out(A) instead of trying to deliver the actual file. When shipping such an Url there are 2 fields in the #arg record which are especially interesting. If we have the following code in "myappmod.erl":
-module(myappmod). -author('klacke@bluetail.com'). -include("../../include/yaws_api.hrl"). -export([out/1]). box(Str) -> {'div',[{class,"box"}], {pre,[],Str}}. out(A) -> {ehtml, [{p,[], box(io_lib:format("A#arg.appmoddata = ~p~n" "A#arg.appmod_prepath = ~p~n" "A#arg.querydata = ~p~n", [A#arg.appmoddata, A#arg.appmod_prepath, A#arg.querydata]))}]}.
The #arg field called "appmoddata" contains the remainder of the path following the encountered appmod and the field "appmod_prepath" contains the part of the URL path leading up to the appmod.
Thus the following URL
http://www.example.org/zap/pathelem/foo/bar/x.pdf?a=b
Produces the following output:
A#arg.appmoddata = "/foo/bar/x.pdf" A#arg.appmod_prepath = "/zap/" A#arg.querydata = "a=b"
Appmods would typically be used by web applications that want to provide the illusion of proper paths to the browser.
A special case of an appmod that is particularly interesting is the '/' appmod. This is used when we want the application code to handle all requests. This is common with web frameworks such as Nitrogen.
<server tita> port = 8001 listen = 0.0.0.0 docroot = /home/klacke/yaws/yaws/scripts/../www appmods = </, myappmod> </server>
The above configuration snippet is an example of a slash appmod. One complication with the slash appmod is that usually we have a set of folders containing static data, images and java script, and we want yaws to just deliver those files without intervention from the slash appmod. This can be achieved by excluding a set of directories.
<server tita> port = 8001 listen = 0.0.0.0 docroot = /home/klacke/yaws/yaws/scripts/../www appmods = </, myappmod exclude_paths icons js top/static> </server>
The above configuration will invoke the 'myappmod' erlang module on everything except any file found in directories 'icons', 'js' and 'top/static' relative to the docroot