Reputation: 313
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!
Upvotes: 4
Views: 244
Reputation: 20014
Compiling your appmod is a matter of calling the erlc
compiler. You then install the resulting beam file into a load directory known to Yaws, which are specified in the yaws.conf
file using the ebin_dir
directive:
ebin_dir = /path/to/some/ebin
ebin_dir = /path/to/another/ebin
You can specify your own paths here. Multiple ebin_dir
settings 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 sync
project.
The URL for your appmod is also specified in yaws.conf
, in a server
block, using the appmods
directive. 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:
<server foo>
port = 8001
listen = 0.0.0.0
docroot = /filesystem/path/to/www
appmods = </, myappmod>
</server>
Note also the optional exclude_paths
directive you can specify in an appmods
setting, typically used for excluding paths storing statically loaded resources. For example, the following setting means that myappmod
handles the entire URL space /
except for any URL path starting with /icons
:
appmods = </, myappmod exclude_paths icons>
Upvotes: 4