编译和运行Yaws appmods

时间:2015-10-15 08:08:17

标签: erlang otp yaws erlangweb

Appmod是让应用程序程序员控制URL路径的一种方法。它们被实现为Erlang模块。例如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.

我应该如何进行编译以使这个appmod易于管理?

我应该在yaws目录树的哪个目录中保存myappmod.erl以及myappmod.beam在编译后的位置?

如何生成引用此appmod的URL路径?

欢迎所有帮助!

1 个答案:

答案 0 :(得分:3)

编辑appmod是调用erlc compiler的问题。然后,将生成的梁文件安装到Yaws已知的加载目录中,该目录使用yaws.conf指令在ebin_dir文件中指定:

ebin_dir = /path/to/some/ebin
ebin_dir = /path/to/another/ebin

您可以在此处指定自己的路径。多个ebin_dir设置是累积的 - 所有此类路径都会添加到Yaws加载路径中。

要积极开发您的appmod,并自动重新加载更改,您可以使用the sync project之类的内容。

您的appmod的网址也在yaws.conf中的server块中使用appmods指令指定。您可以在Yaws documentation中找到示例。例如,如果您希望appmod控制服务器的整个URL空间,请指定/作为其URL路径:

<server foo>
    port = 8001
    listen = 0.0.0.0
    docroot = /filesystem/path/to/www
    appmods = </, myappmod>
</server>

还要注意可以在exclude_paths设置中指定的可选appmods指令,通常用于排除存储静态加载资源的路径。例如,以下设置表示myappmod处理整个网址空间/,但以/icons开头的任何网址路径除外:

appmods = </, myappmod exclude_paths icons>
相关问题