diff src/luan/modules/http/Server.luan @ 1256:c147e2e877e3

allow subclassing of HttpServicer
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 19 Sep 2018 20:15:16 -0600
parents e55a0c3696fb
children 3f4644246e39
line wrap: on
line diff
--- a/src/luan/modules/http/Server.luan	Mon Sep 03 06:13:55 2018 -0600
+++ b/src/luan/modules/http/Server.luan	Wed Sep 19 20:15:16 2018 -0600
@@ -30,20 +30,14 @@
 local Server = {}
 
 function Server.init_dir(dir)
-	local dir_uri, dir_path
-	if matches(dir,":") then
-		dir_uri = dir
-		dir_path = match(dir,"^file:(.*)$") or error "server dir must be scheme 'file:'"
-	else
-		dir_path = dir
-		dir_uri = "file:"..dir
+	if not matches(dir,":") then
+		dir = "file:"..dir
 	end
-	dir_uri = gsub(dir_uri,"/$","")  -- remove trailing '/' if any
-	Http.dir = dir_uri
+	dir = gsub(dir,"/$","")  -- remove trailing '/' if any
+	Http.dir = dir
 	function Io.schemes.site(path)
-		return Io.uri( dir_uri..path )
+		return Io.uri( dir..path )
 	end
-	return dir_path
 end
 
 function Server.start()
@@ -68,7 +62,8 @@
 
 function Server.serve(dir,port)
 	port = port or 8080
-	local dir_path = Server.init_dir(dir)
+	Server.init_dir(dir)
+	local dir_path = match(Http.dir,"^file:(.*)$") or error "server dir must be scheme 'file:'"
 	local file_handler = FileHandler.new(dir_path)
 	local dir_handler = DirHandler.new(file_handler)
 	local luan_handler = LuanHandler.new()