【问题标题】:Compiling and running Yaws appmods编译和运行 Yaws appmods
【发布时间】:2016-01-13 14:16:30
【问题描述】:

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 易于管理?

myappmod.erl 应该保存在 yaws 目录树的哪个目录下,编译后 myappmod.beam 到哪里去了?

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

欢迎所有帮助!

【问题讨论】:

    标签: erlang erlang-otp yaws erlangweb


    【解决方案1】:

    编译您的 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 的 URL 也在 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处理整个URL空间/,除了任何以/icons开头的URL路径:

    appmods = </, myappmod exclude_paths icons>
    

    【讨论】:

    • @Vinoski 该解决方案非常有帮助。谢谢!
    • 这很有帮助。谢谢
    猜你喜欢
    • 2017-03-30
    • 2012-07-03
    • 2020-02-02
    • 2014-07-28
    • 2013-08-19
    • 2011-04-23
    • 2011-07-15
    • 2017-06-06
    • 1970-01-01
    相关资源
    最近更新 更多