benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 113 forks source link

Couchbeam and YAWS #77

Closed Nesh108 closed 12 years ago

Nesh108 commented 12 years ago

Hello! 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>
Nesh108 commented 12 years ago

I fixed it by running these:

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).

benoitc commented 12 years ago

Hrm you shouldn't need to start all these applications. It may be better to add needed dependencied to your erlang release or use couchbeam:start() which start dependencies .

Nesh108 commented 12 years ago

Yeah, that worked. The result is exactly the same but is it indeed shorter and probably better to understand. Thanks :)

benoitc commented 12 years ago

np :) closing the issue then :)