0

I am here because I am trying to use Couchbeam form my page on a YAWS. I have tested CB and it worked correctly from Terminal, using:

erl -pa ebin -pa deps/ibrowse/ebin -s couchbeam

Now I am trying to replicate what I did locally on my webpage. I believe the issue is that I don't know how to tell erl to do 'erl -pa ebin -pa deps/ibrowse/ebin -s couchbeam' from a yaws page.

I have tried to simply running all the needed apps, but I am getting this:

Stack: [{ibrowse_lib,url_encode,["test"],[]},
{couchbeam,save_doc,3,[{file,"src/couchbeam.erl"},{line,383}]},
{m50,out,1,
     [{file,"/Users/Nesh/.yaws/yaws/default/m50.erl"},{line,35}]},
{yaws_server,deliver_dyn_part,8,
             [{file,"yaws_server.erl"},{line,2647}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1152}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1013}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]

This is my erl code:

<erl>


 startApp() ->
 application:start(crypto),
 application:start(private_key),
 application:start(ssl),
 application:start(sasl), 
 application:start(ibrowse),
 application:start(couchbeam).



out(Arg) ->
startApp(),

Host = "localhost",
Port = 5984,
Prefix = "",
Options = [],
S = couchbeam:server_connection(Host, Port, Prefix, Options),

Options = [],{ok, Db} = couchbeam:open_db(S, "erlang", Options),

Doc = {[{<<"_id">>, <<"test">>},{<<"content">>, <<"web text">>}]},
{ok, Doc1} = couchbeam:save_doc(Db, Doc).


</erl>
N3sh
  • 881
  • 8
  • 37

2 Answers2

1

I wouldn't recommend running Couchbeam from within a .yaws page like this. You should instead either create an Erlang release such that Couchbeam and Yaws are both executed within the same Erlang VM and then use a Yaws appmod to call into Couchbeam, or maybe you should consider making Couchbeam a bootstrap yapp for Yaws.

If you really think you're having load path problems, you can specify load paths in the yaws.conf file via the ebin_dir directive. For example:

ebin_dir = deps/ibrowse/bin
ebin_dir = couchbeam/ebin

But the stack trace you show seems like it's missing something, so it's hard to tell you exactly what's wrong.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
0

I managed to fix it doing this:

I've added these lines in yaws.conf:

ebin_dir = /usr/local/var/yaws/couchbeam/deps/ibrowse/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/deps/jiffy/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/deps/mochiweb/ebin
ebin_dir = /usr/local/var/yaws/couchbeam/ebin

Note: I put the folder 'couchbeam' in /usr/local/var/yaws/

then I modified the code in this way:

load_deps() ->

application:start(sasl),
application:start(ibrowse),
application:start(jiffy),
application:start(inets),
application:start(xmerl),
application:start(compiler),
application:start(syntax_tools),
application:start(mochiweb),
application:start(couchbeam).


out(Arg) ->

load_deps(),
Host = "localhost",
Port = 5984,
Prefix = "",
Options = [],
S = couchbeam:server_connection(Host, Port, Prefix, Options),

Options = [],{ok, Db} = couchbeam:open_db(S, "erlang", Options),

Doc = {[{<<"content">>, <<"Checking webpage">>}]},
{ok, Doc1} = couchbeam:save_doc(Db, Doc),

{html, "Document has been added"}.


</erl>
N3sh
  • 881
  • 8
  • 37