nitcorn: improve default file listing of `FileServer`
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 17 Sep 2014 20:45:40 +0000 (16:45 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 18 Sep 2014 16:17:53 +0000 (12:17 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/nitcorn/file_server.nit

index 6c6d39c..3552b2d 100644 (file)
@@ -106,14 +106,15 @@ class FileServer
                                        var files = local_file.files
 
                                        var links = new Array[String]
-                                       if local_file.length > 1 then
-                                               # The extra / is a hack
-                                               var path = "/" + (turi + "/..").simplify_path
-                                               links.add "<a href=\"{path}\">..</a>"
+                                       if turi.length > 1 then
+                                               var path = (request.uri + "/..").simplify_path
+                                               links.add "<a href=\"{path}/\">..</a>"
                                        end
                                        for file in files do
-                                               var path = (turi + "/" + file).simplify_path
-                                               links.add "<a href=\"{path}\">{file}</a>"
+                                               var local_path = local_file.join_path(file).simplify_path
+                                               var web_path = file.simplify_path
+                                               if local_path.file_stat.is_dir then web_path = web_path + "/"
+                                               links.add "<a href=\"{web_path}\">{file}</a>"
                                        end
 
                                        var header = self.header