Appmods are a way to let the application programmer take control over the URL path. They are implemented as Erlang modules. For example myappmod.erl
-module(myappmod).
-include("../../yaws_api.hrl").
-compile(export_all).
out(Arg) ->
Method = (Arg#arg.req)#http_request.method,
handle(Method, Arg).
handle(Method,Arg) ->
%% Do something
ok.
How should I carry out the compiling to make this appmod easily manageable?
In which directory of the yaws directory tree should I save the myappmod.erl and where does the myappmod.beam go after compiling?
How do generate the URL path to refer to this appmod?
All the help is welcomed!
Compiling your appmod is a matter of calling the
erlccompiler. You then install the resulting beam file into a load directory known to Yaws, which are specified in theyaws.conffile using theebin_dirdirective:You can specify your own paths here. Multiple
ebin_dirsettings are cumulative — all such paths are added to the Yaws load path.For actively developing your appmod, with automatic reloading of your changes, you can use something like the
syncproject.The URL for your appmod is also specified in
yaws.conf, in aserverblock, using theappmodsdirective. You can find examples in the Yaws documentation. For example, if you want your appmod to control the whole URL space for a server, you specify/as its URL path:Note also the optional
exclude_pathsdirective you can specify in anappmodssetting, typically used for excluding paths storing statically loaded resources. For example, the following setting means thatmyappmodhandles the entire URL space/except for any URL path starting with/icons: