好吧,我在这里做错了什么。我正在试用http://yaws.hyber.org/embed.yaws中嵌入式YAW的简单示例,但是使用了一个appmod。我添加了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}]}]
答案 0 :(得分:5)
堆栈跟踪显示您的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
文件是否存在。