changeset 1172:1aa6dd74f3fc

add serve_for_nginx
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 11 Feb 2018 03:19:45 -0700
parents 794ddcfbee20
children bdbd1d12c1f2
files src/luan/modules/http/Server.luan src/luan/modules/http/serve.luan src/luan/modules/http/serve_for_nginx.luan
diffstat 3 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/Server.luan	Sun Feb 11 02:41:23 2018 -0700
+++ b/src/luan/modules/http/Server.luan	Sun Feb 11 03:19:45 2018 -0700
@@ -30,7 +30,7 @@
 
 Server.port = 8080
 
-function Server.init(dir)
+local function init_dir(dir)
 	local dir_uri, dir_path
 	if matches(dir,":") then
 		dir_uri = dir
@@ -44,6 +44,11 @@
 	function Io.schemes.site(path)
 		return Io.uri( dir_uri..path )
 	end
+	return dir_path
+end
+
+function Server.init(dir)
+	local dir_path = init_dir(dir)
 	local file_handler = FileHandler.new(dir_path)
 	local dir_handler = DirHandler.new(file_handler)
 	local luan_handler = LuanHandler.new()
@@ -75,4 +80,20 @@
 	Server.start()
 end
 
+function Server.serve_for_nginx(dir)
+	init_dir(dir)
+	local luan_handler = LuanHandler.new()
+	local not_found_hander = NotFound.new(luan_handler)
+	local handler = luan_handler
+	handler = IndexHandler.new(handler)
+	handler = ListHandler.new( handler, not_found_hander )
+	handler = ContentTypeHandler.new(handler)
+	handler = SafeHandler.new(handler)
+	handler = LogHandler.new(handler)
+	Server.server = JavaServer.new(Server.port,handler)
+
+	Server.start_rpc()
+	Server.start()
+end
+
 return Server
--- a/src/luan/modules/http/serve.luan	Sun Feb 11 02:41:23 2018 -0700
+++ b/src/luan/modules/http/serve.luan	Sun Feb 11 03:19:45 2018 -0700
@@ -2,7 +2,7 @@
 local Server = require "luan:http/Server.luan"
 
 if #{...} ~= 1 then
-	Io.stderr.write "usage: luan luan:http/serve dir-URI\n"
+	Io.stderr.write "usage: luan luan:http/serve dir\n"
 	return
 end
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/modules/http/serve_for_nginx.luan	Sun Feb 11 03:19:45 2018 -0700
@@ -0,0 +1,9 @@
+local Io = require "luan:Io.luan"
+local Server = require "luan:http/Server.luan"
+
+if #{...} ~= 1 then
+	Io.stderr.write "usage: luan luan:http/serve_for_nginx dir\n"
+	return
+end
+
+Server.serve_for_nginx(...)