Working example for Erlang server interface

I am trying to get Erlang Inets mode_esi to work and run some function. So, far, I did not succeed. Can someone post a minimal example of how to run Inets so that the type url invokes the http:localhost:8099/esi/my_mod:foomethod my_mod:foo/3?

Addition: I 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]}}]).

Module:

-module(my_esi).
-export([foo/3]).
foo(Sid, Env, In) -> mod_esi:deliver(Sid, ["bla"]).

But looking in http://localhost:8099/esi/my_esi:fooleads to an error message.

+3
source share
3 answers

. - , , , Inets ( inets/examples/server_root/conf/8080.conf). , , Inets, , inets:start(httpd, [...]). - Inets , .

+1

, ( ). , Google, , ;)

:

# filename: my_esi.erl
-module(my_esi).
-export([foo/3,bar/3]).
foo(Sid, Env, In) -> mod_esi:deliver(Sid, ["foo"]).
bar(Sid, Env, In) -> mod_esi:deliver(Sid, ["bar"]).

, :

erlc my_esi.erl

my_esi.beam

bash

erl

:

inets:start().
{Httpd_State,Httpd_Pid} = inets:start(httpd, [{port, 8099}, {server_name, "localhost"}, {document_root, "."}, {modules,[mod_esi]},{server_root, "."}, {erl_script_alias, {"/esi", [my_esi, io]}}]).

:

{modules,[mod_esi]}

, , .

, /:

, , , . , :

modules()       -> [atom()]

:

{modules, [mod_access, mod_esi, ..., etc.]}

, -:)

+1

, :

  • {erl_script_alias, {"/esi", [my_mod]}} - inets, .
  • my_mod. - :

    -module(my_mod).
    -export([foo/3]).
    
    
    foo(SessID, _Env, _Input) ->
      mod_esi:deliver(SessID, ["Data ", <<"as">>, " an iolist"]).
    
  • , mod_esi inets, : {modules, [.., mod_esi, ..}}
  • : 3 , " , , ". .
  • . . .
  • -.
0

Source: https://habr.com/ru/post/1777180/


All Articles