klacke/yaws — Issue #66: dynamic content doesn't work if server running with id other than "default"
Author: yzh44yzh
Created: 2011-10-23 13:39:34+00:00
State: open

Hello.

I am using yaws in embedded mode in my app. I run it like this:

run() ->
Id = "my_server",
GconfList = [{id, Id},
{logdir, "./logs"},
{ebin_dir, ["./ebin"]}],
Docroot = "./wwwroot",
SconfList = [{port, 8888},
{servername, Id},
{listen, {127,0,0,1}},
{docroot, Docroot}],
{ok, SCList, GC, ChildSpecs} = yaws_api:embedded_start_conf(
Docroot, SconfList, GconfList, Id),
[supervisor:start_child(test_echo_sup, Ch) || Ch <- ChildSpecs],
yaws_api:setconf(GC, SCList).

It works ok with static pages, but when I try to open dynamic page it gives an error:

=ERROR REPORT==== 23-Oct-2011::16:35:13 ===
Yaws process died: {{badmatch,{error,enoent}},
[{yaws_compile,new_out_file,4},
{yaws_compile,compile_file,7},
{yaws_compile,'-compile_file/1-fun-0-',3},
{global,trans,4},
{yaws_server,do_yaws,4},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p_do_apply,3}]}

I find out that error goes from here:
yaws_compile.erl line 312
new_out_file(Line, C, Tail, GC) ->
Module = new_out_file_module(Tail),
OutFile = new_out_file_name(Module, GC),
?Debug("Writing outout file~s~n", [OutFile]),
{ok, Out} = file:open(OutFile, [write]),

I build yaws with debug mode enabled and saw it tries to open file
~/.yaws/yaws/my_server/m1.erl
but there is no "my_server" dir in ~/.yaws/yaws. There is only "default" dir here.

After creating "my_server" dir manually, yaws works properly.

So the problem is that yaws doesn't create all directories when compile new module.