On Sun, Sep 13, 2009 at 10:58 AM, Ozgur <hinoglu@gmail.com> wrote:
Hi

It's been a few days with erlang, and one day with yaws, so please warn me if i'm digging
the wrong hole :)

Considering replacing my lighttpd+django setups with yaws+django, i began playing with yaws yesterday.
By following the rails on yaws example setting at http://wiki.github.com/klacke/yaws/run-rails-under-yaws
managed to run django with fcgi on yaws. One thing that bugged me was, all the requests are passed to
fcgi instance, whether it's dynamic or static content request, causing unnecessary load on fcgi app.
see snippet below

out(Arg) ->
   case yaws_cgi:call_fcgi_responder(Arg) of
       R when is_list(R) ->
           case proplists:get_value(status, R) of
               404 -> {page, Arg#arg.server_path};  % Let Yaws try to serve static files
               _   -> R
           end;

       X -> X
   end.

i've added a per-server "static_paths" parameter to yaws.conf. sample usage below
 <server blah>
 ...
 static_paths = /media/, /files/
 </server

which enables some more control over the static content handling in my django appmod. snippet below

...
out(Arg) ->
   case lists:filter(fun(Y) -> string:rstr(Arg#arg.server_path, Y) =/= 0 end, Arg#arg.static_paths) of
       [_|_] ->
       %% serve static
       error_logger:info_msg("static serving ~p~n",[Arg#arg.server_path]),
       {page, Arg#arg.server_path};
       _ ->

           error_logger:info_msg("dynamic serving ~p~n",[Arg#arg.server_path]),
           case yaws_cgi:call_fcgi_responder(Arg) of
               R when is_list(R) ->
                   case proplists:get_value(status, R) of
                   404 ->
                       {page, Arg#arg.server_path}; % Let Yaws try to serve static files
                   _  -> R
                   end;

               X -> X
           end
   end.

I don't think it's necessary to add a new field to the server conf for this. An easy way to do this is to examine the URI in the Arg parameter of your out() function to see if the request is targeting one of your static paths, and take appropriate action if it is. If you'd rather keep the list of static paths out of your code so it can be easily changed, you could use the opaque field of the server conf and set it to whatever you like. You could also use a yapp instead of an appmod and keep the list of static paths as part of the environment in your .app file.

Can you try one of these approaches instead and see how you get on, then let us know?

--steve