gpt4 book ai didi

erlang - 嵌入了 appmod 的 YAW 对我不起作用

转载 作者:行者123 更新时间:2023-12-01 11:30:44 25 4
gpt4 key购买 nike

好吧,我做错了什么。我正在尝试来自 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}]}]

最佳答案

堆栈跟踪显示您的 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 文件位于该目录中。

关于erlang - 嵌入了 appmod 的 YAW 对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32303424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com