4

Appmods 是一种让应用程序程序员控制 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 路径?

欢迎所有帮助!

4

1 回答 1

4

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>
于 2015-10-15T16:44:30.073 回答