【发布时间】:2017-03-20 03:49:57
【问题描述】:
我有一个 .yaws 文件,它从我编写的 authenticate 模块中调用 setup/0 函数,该模块已放在 ebin 目录中。当我从 Erlang shell 调用 authenticate:setup/0 时,它创建了一个表就好了,但是当我在浏览器中加载 something.yaws 时,它调用了 authenticate:setup/0 函数,它返回 {aborted,{bad_type,users,disc_copies,nonode@nohost}} (something.yaws 只是返回返回authenticate:setup/0 的值嵌入到 html 中用于调试目的)。
这是setup/0 函数:
setup() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(users, [{type, set}, {record_name, user}, {disc_copies, [node()]}, {attributes, record_info(fields, user)}]).
这是user 记录:
-record(user, {username, hashed_pw, salt}).
(在浏览器中尝试过之后,我尝试从 Erlang shell 调用它,所以不会干扰它。)
如果我运行yaws --mnesiadir /usr/local/lib/yaws-appmods/mnesia/,我会得到
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:true]
Eshell V8.1 (abort with ^G)
1>
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using config file /etc/yaws/yaws.conf
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using global subconfig file /etc/yaws/conf.d/localhost.conf
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Ctlfile : /home/username/.yaws/yaws/default/CTL
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Listening to 0.0.0.0:8080 for <1> virtual servers:
- http://localhost:8080 under /usr/share/yaws/www
rd(user, {username, hashed_pw, salt}).
user
2> mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(users, [{type, set}, {record_name, user}, {disc_copies, [node()]}, {attributes, record_info(fields, user)}]).
{aborted,{bad_type,users,disc_copies,nonode@nohost}}
如果我在以erl -mnesia dir '"/usr/local/lib/yaws-appmods/mnesia/"' 开头的 Erlang shell 中运行相同的 erlang 代码,它就可以正常工作。
【问题讨论】:
标签: web erlang mnesia yaws erlang-shell