erlyaws / yaws

Yaws webserver
https://erlyaws.github.io
BSD 3-Clause "New" or "Revised" License
1.28k stars 268 forks source link

yapps appmod exclude_dir is absolute #103

Closed kristofferkoch closed 12 years ago

kristofferkoch commented 12 years ago

I tried to create a yapp with a root appmod:

{application, testapp,
 [{description,"testapp"},
  {vsn,"0.1"},
  {modules,[]},
  {registered, []},
  {env, [{yapp_appmods,[{"/", testapp_amod, [["static"]]}]}]}
 ]
}.

However, the static folder only works if the exclude_dir is absolute:

  {env, [{yapp_appmods,[{"/", testapp_amod, [["path_to_yapp","static"]]}]}]}
vinoski commented 12 years ago

Would you mind trying the patch below to see if it fixes the problem?

diff --git a/applications/yapp/src/yapp.erl b/applications/yapp/src/yapp.erl
index 7e2abe9..ef43f8f 100644
--- a/applications/yapp/src/yapp.erl
+++ b/applications/yapp/src/yapp.erl
@@ -116,7 +116,12 @@ arg_rewrite(Arg) ->
             SC = get(sc),
             AppMods = SC#sconf.appmods,
             Opaque = SC#sconf.opaque,
-            SC2 = SC#sconf{docroot=Docroot, appmods = AppMods ++ YappMods,
+            RemappedYappMods = lists:map(fun({PE, Mod, Ex}) ->
+                                                 {PE, Mod, YappPath ++ Ex};
+                                            (AM) ->
+                                                 AM
+                                         end, YappMods),
+            SC2 = SC#sconf{docroot=Docroot, appmods = AppMods ++ RemappedYappMods,
                            opaque = AddOpaque ++ Opaque},
             put(sc, SC2),

Just cd to the topmost directory of your yaws repository, paste the patch into a file, and run "patch -p1 <file" where "file" is the file you created to hold the patch. Then recompile the yapp application, redeploy it, and see if the fix works. Thanks in advance.

kristofferkoch commented 12 years ago

Hi, sorry for answering so late, but I've been busy with other things.

The idea of the patch is correct, but Ex above is a list of lists. In addition, I found that the leading slash of YappPath must be stripped, so the the patch "works for me" when adjusted a bit:

            [$/|YappPathTail] = YappPath,
            RemappedYappMods = lists:map(fun({PE, Mod, Ex}) ->
                                                 {PE, Mod, [[YappPathTail] ++ X || X <- Ex]};
                                            (AM) ->
                                                 AM
                                         end, YappMods),

I'm btw. impressed with the prompt response I got on this, to bad I didn't follow up as fast :)

vinoski commented 12 years ago

The fix is now on master. Thanks to Mikael Karlsson for the patch and to @kristofferkoch for helping verify it.