繁体   English   中英

嵌入appmod的YAW不适合我

[英]YAWs embedded with appmod not working for me

好吧,我在这里做错了什么。 我正在尝试从http://yaws.hyber.org/embed.yaws中使用appmod的嵌入式YAW的简单示例。 我添加了my_app.erl文件并进行了编译。 如果没有嵌入式YAW,它可以工作,所以我认为它是嵌入式的。

-module(ybed).
-compile(export_all).

start() ->
    {ok, spawn(?MODULE, run, [])}.

run() ->
    Id = "embedded",
    GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],
    Docroot = "/Users/someuser/yawstest",
    SconfList = [{port, 8888},
                 {listen, {0,0,0,0}},
                 {docroot, Docroot},
                 {appmods, [{"/", my_app}]}
                ],
    {ok, SCList, GC, ChildSpecs} =
        yaws_api:embedded_start_conf(Docroot, SconfList, GconfList),
    [supervisor:start_child(ybed_sup, Ch) || Ch <- ChildSpecs],
    yaws_api:setconf(GC, SCList),
    {ok, self()}.

得到此错误:

ERROR erlang code threw an uncaught exception:
 File: appmod:0
Class: error
Exception: undef
Req: {http_request,'GET',{abs_path,"/demo"},{1,1}}
Stack: [{my_app,out,
            [{arg,#Port<0.2721>,
                 {{127,0,0,1},63720},
                 {headers,"keep-alive",
                     "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                     "0.0.0.0:8888",undefined,undefined,undefined,undefined,
                     undefined,undefined,undefined,
                     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0",
                     undefined,[],undefined,undefined,undefined,undefined,
                     undefined,undefined,undefined,undefined,
                     [{http_header,0,"Dnt",undefined,"1"},
                      {http_header,10,'Accept-Encoding',undefined,
                          "gzip, deflate"},
                      {http_header,11,'Accept-Language',undefined,"null"}]},
                 {http_request,'GET',{abs_path,"/demo"},{1,1}},
                 {http_request,'GET',{abs_path,"/demo"},{1,1}},
                 undefined,"/demo",undefined,undefined,
                 "/Users/someuser/yawstest","/",
                 "/Users/someuser/yawstest/demo",undefined,undefined,
                 <0.63.0>,[],"/","/",undefined}],
            []},
        {yaws_server,deliver_dyn_part,8,
            [{file,"yaws_server.erl"},{line,2818}]},
        {yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1232}]},
        {yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1068}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]

堆栈跟踪显示你的my_app:out/1函数被调用,但你得到一个undef异常。 发生这种情况是因为运行时无法找到my_app:out/1函数,这意味着它无法找到模块或模块存在但不会导出out/1函数。 例如,我可以通过不提供my_app模块使用示例代码复制错误。

首先,确保my_app.erl文件导出out/1函数。 这是一个简单的问题,只为所有请求返回405错误:

-module(my_app).
-export([out/1]).

out(_Arg) ->
    {status, 405}.

编译my_app.erl文件并将已编译的my_app.beam文件放在Erlang运行时已知的加载路径中,或放在加载到加载路径的目录中。 在您的代码中,您似乎正在尝试后一种方法,因为您专门使用此Yaws全局配置指令添加ebin_dir

GconfList = [{ebin_dir, ["/Users/someuser/yawsembedded/ebin"]}],

您需要验证/Users/someuser/yawsembedded/ebin目录是否存在,以及编译的my_app.beam文件是否位于此处。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM