changeset 1281:7fc83fd2a39a

http/Server cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 20 Dec 2018 14:09:19 -0700
parents 781ec0a92bb5
children 2531942abaf3
files src/luan/modules/http/Server.luan src/luan/modules/http/serve.luan src/luan/modules/http/test.luan
diffstat 3 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
diff -r 781ec0a92bb5 -r 7fc83fd2a39a src/luan/modules/http/Server.luan
--- a/src/luan/modules/http/Server.luan	Thu Dec 20 13:38:16 2018 -0700
+++ b/src/luan/modules/http/Server.luan	Thu Dec 20 14:09:19 2018 -0700
@@ -40,10 +40,10 @@
 	end
 end
 
-function Server.start()
+local function start(server)
 	try {
 		function()
-			LuanHandler.start(Server.server)
+			LuanHandler.start(server)
 		end
 		catch = function(e)
 --			e.java.printStackTrace();
@@ -53,9 +53,9 @@
 	}
 end
 
-function Server.start_rpc()
+function Server.start_rpc(luan_handler)
 	function Rpc.functions.call(domain,fn_name,...)
-		return Server.luan_handler.call_rpc(fn_name,...)
+		return luan_handler.call_rpc(fn_name,...)
 	end
 	Thread.fork(Rpc.serve)
 end
@@ -74,20 +74,21 @@
 	handler = ContentTypeHandler.new(handler)
 	handler = SafeHandler.new(handler)
 	handler = LogHandler.new(handler)
-	Server.server = JavaServer.new(port,handler)
-	Server.start()
-	Server.start_rpc()
+	local server = JavaServer.new(port,handler)
+	start(server)
+	return server, luan_handler
 end
 
 function Server.serve_for_proxy(dir,port)
 	port = port or 8080
 	Server.init_dir(dir)
-	local handler = LuanHandler.new()
-	handler = IndexHandler.new(handler)
+	local luan_handler = LuanHandler.new()
+	local handler = IndexHandler.new(luan_handler)
 	handler = ContentTypeHandler.new(handler)
 	handler = SafeHandler.new(handler)
-	Server.server = JavaServer.new(port,handler)
-	Server.start()
+	local server = JavaServer.new(port,handler)
+	start(server)
+	return server, luan_handler
 end
 
 return Server
diff -r 781ec0a92bb5 -r 7fc83fd2a39a src/luan/modules/http/serve.luan
--- a/src/luan/modules/http/serve.luan	Thu Dec 20 13:38:16 2018 -0700
+++ b/src/luan/modules/http/serve.luan	Thu Dec 20 14:09:19 2018 -0700
@@ -4,7 +4,7 @@
 
 
 if #{...} ~= 1 then
-	Io.stderr.write "usage: luan luan:http/serve dir\n"
+	Io.stderr.write "usage: luan luan:http/serve.luan dir\n"
 	return
 end
 
diff -r 781ec0a92bb5 -r 7fc83fd2a39a src/luan/modules/http/test.luan
--- a/src/luan/modules/http/test.luan	Thu Dec 20 13:38:16 2018 -0700
+++ b/src/luan/modules/http/test.luan	Thu Dec 20 14:09:19 2018 -0700
@@ -5,7 +5,7 @@
 
 
 if #{...} ~= 2 then
-	Io.stderr.write "usage: luan luan:http/serve dir test-URI\n"
+	Io.stderr.write "usage: luan luan:http/test.luan dir test-URI\n"
 	return
 end