简体   繁体   English

嵌入appmod的YAW不适合我

[英]YAWs embedded with appmod not working for me

Alright, what am I doing wrong here. 好吧,我在这里做错了什么。 I'm trying the simple example of embedded YAWs from http://yaws.hyber.org/embed.yaws but with an appmod. 我正在尝试从http://yaws.hyber.org/embed.yaws中使用appmod的嵌入式YAW的简单示例。 I've added the my_app.erl file and compiled it. 我添加了my_app.erl文件并进行了编译。 It works if not in embedded YAWs so I think it is specific to embedded. 如果没有嵌入式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()}.

Getting this Error: 得到此错误:

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}]}]

The stack trace shows that your my_app:out/1 function is getting called, but you're getting an undef exception. 堆栈跟踪显示你的my_app:out/1函数被调用,但你得到一个undef异常。 This is occurring because the runtime can't find the my_app:out/1 function, which means either it can't find the module or the module exists but does not export an out/1 function. 发生这种情况是因为运行时无法找到my_app:out/1函数,这意味着它无法找到模块或模块存在但不会导出out/1函数。 For example, I was able to duplicate the error using the example code by not providing a my_app module. 例如,我可以通过不提供my_app模块使用示例代码复制错误。

First, make sure your my_app.erl file exports an out/1 function. 首先,确保my_app.erl文件导出out/1函数。 Here's a trivial one that just returns a 405 error for all requests: 这是一个简单的问题,只为所有请求返回405错误:

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

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

Compile your my_app.erl file and put the compiled my_app.beam file either in a load path already known to the Erlang runtime, or in a directory you add to the load path. 编译my_app.erl文件并将已编译的my_app.beam文件放在Erlang运行时已知的加载路径中,或放在加载到加载路径的目录中。 In your code it appears you're trying the latter approach, since you're specifically adding an ebin_dir with this Yaws global configuration directive: 在您的代码中,您似乎正在尝试后一种方法,因为您专门使用此Yaws全局配置指令添加ebin_dir

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

You need to verify that the /Users/someuser/yawsembedded/ebin directory exists, and that the compiled my_app.beam file is located there. 您需要验证/Users/someuser/yawsembedded/ebin目录是否存在,以及编译的my_app.beam文件是否位于此处。

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

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