Erlang 服务器接口的工作示例
我正在尝试使 Erlang 的 Inets mode_esi 工作并运行一些函数。到目前为止,我还没有成功。有人可以发布一个关于如何运行 Inets 的最小示例,以便像 http:localhost:8099/esi/my_mod:foo
这样的 url 将调用方法 my_mod:foo/3
?
另外:我已经使用这些命令启动了 inets:
inets:start(),
inets:start(httpd, [{port, 8099}, {server_name, "localhost"}, {document_root, "."},
{server_root, "."}, {erl_script_alias, {"/esi", [my_esi, io]}}]).
该模块是:
-module(my_esi).
-export([foo/3]).
foo(Sid, Env, In) -> mod_esi:deliver(Sid, ["bla"]).
但是浏览到 http://localhost:8099/esi/my_esi:foo
会导致错误消息。
I am trying to make Erlang's Inets mode_esi work and run some function. So, far, I did not succeed. Can someone post a minimal example of how to run Inets so that a url like http:localhost:8099/esi/my_mod:foo
will invoke the method my_mod:foo/3
?
Addition: I have started inets with these commands:
inets:start(),
inets:start(httpd, [{port, 8099}, {server_name, "localhost"}, {document_root, "."},
{server_root, "."}, {erl_script_alias, {"/esi", [my_esi, io]}}]).
The module is:
-module(my_esi).
-export([foo/3]).
foo(Sid, Env, In) -> mod_esi:deliver(Sid, ["bla"]).
But browsing to http://localhost:8099/esi/my_esi:foo
result in an error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了澄清已经说过的内容,我将给出一个工作示例(从头开始)。这是为了帮助那些从 google 来到这里的人,主要是因为我就是这样找到它的;)
首先,创建模块:
保存它,然后编译它:
您现在将拥有 my_esi.beam
运行 shell
然后从 bash在 shell 内 输入以下内容:
这里重要的部分是:
如果您需要其他模块,请通过将它们附加到列表来加载它们。
为了澄清如何/为什么:
我首先承认它一开始确实看起来有点奇怪,而且文档没有我希望的那么有帮助。然而,我意识到:
变成:
希望它能帮助别人:)
To clarify what has already been said, I'll give a working example (from the ground up). This is to help those who came here from google, mostly because it's how I found it ;)
First, create the module:
Save it, then compile it:
You'll now have my_esi.beam
Then run the shell from bash
Within the shell type the following:
The important part here is:
If you need other modules, load them by appending them to the list.
To clarify how/why:
I will first admit that it does seems a bit strange at first, and that the documentation was less helpful than I had hoped. However, I realised that:
becomes:
Hope it helps someone :)
我自己已经解决了。由于某种原因,超出了我的理解,当我使用配置文件(
inets/examples/server_root/conf/8080.conf
的修改版本)调用 Inets 时,完全相同的代码起作用了。我认为示例文件包含 Inets 所需的属性列表,比我在inets:start(httpd, [...])
中列出的属性更完整。如果将来有人遇到 Inets 问题,我的建议是从示例配置开始。I've solved it myself. For some reason, beyond my understanding, the exact same code worked when I invoked Inets with a configuration file (a modified version of
inets/examples/server_root/conf/8080.conf
). I suppose that the example file includes a more complete list of properties that Inets required than what I listed ininets:start(httpd, [...])
. If anyone encounters Inets problem in the future, my advice is to start with the example configuration.好的,这里是:
inets
Web 服务器设置{erl_script_alias, {"/esi", [my_mod]}}
,以便模块被接受。写入
my_mod
。像这样的东西:<前><代码>-模块(my_mod)。
-导出([foo/3])。
foo(SessID,_Env,_Input)->
mod_esi:deliver(SessID, ["数据", <<"as">>, "一个iolist"])。
mod_esi
是名为 module 的inets
部分的一部分:{modules, [.., mod_esi, ..}}
Ok, here goes:
{erl_script_alias, {"/esi", [my_mod]}}
for theinets
web server, so the module is accepted.Write
my_mod
. Something like:mod_esi
is part ofinets
section called module:{modules, [.., mod_esi, ..}}