diff src/luan/host/jetty/Init.luan @ 1185:94cf2576a922

implement WebHandler for nginx
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 21 Feb 2018 21:22:16 -0700
parents src/luan/host/Init.luan@51d1342e25ad
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/host/jetty/Init.luan	Wed Feb 21 21:22:16 2018 -0700
@@ -0,0 +1,96 @@
+local Package = require "luan:Package.luan"
+Package.loaded["luan:http/Http.luan"] = require "luan:http/jetty/Http.luan"
+
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local String = require "luan:String.luan"
+local gsub = String.gsub or error()
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Hosting = require "luan:host/Hosting.luan"
+local Mail = require "luan:mail/Mail.luan"
+
+
+local Init = {}
+
+local dir, domain = ...
+
+Init.password = Luan.do_file(dir.."/info.luan").password or error()
+
+Http.dir = "file:"..dir.."/site"
+
+function Io.schemes.site(path,loading)
+	return Io.uri( Http.dir..path, loading )
+end
+
+Hosting.domain = domain
+Io.password = Init.password
+
+
+-- logging
+
+java()
+local Logger = require "java:org.apache.log4j.Logger"
+local Logging = require "luan:logging/Logging.luan"
+
+local root = gsub(domain,"\.",":")
+
+Logging.layout = "%d %-5p %c{-1} - %m%n"
+Logging.file = dir.."/site/private/local/logs/luan.log"
+Logging.max_file_size = "1MB"
+local one_mb = 1048576
+
+local log_dir = dir.."/site/private/local/logs/"
+Logging.appenders = {
+	[log_dir.."error.log"] = "ERROR"
+	[log_dir.."warn.log"] = "WARN"
+	[log_dir.."info.log"] = "INFO"
+}
+
+Logging.log4j_root_logger = Logger.getLogger(root)
+Logging.log4j_root_logger.setAdditivity(false)
+
+local old_log_to_file = Logging.log_to_file
+
+function Logging.log_to_file(file,logger_name)
+	Io.schemes.file(file)  -- security check
+	logger_name = logger_name and root .. "." .. logger_name
+	local appender = old_log_to_file(file,logger_name)
+	appender.getMaximumFileSize() <= one_mb or error "Logging.max_file_size is too big"
+	return appender
+end
+
+local old_init = Logging.init
+
+function Logging.init()
+	Logging.appenders["System.err"] = nil
+	Logging.appenders["System.out"] = nil
+	old_init()
+end
+
+Logging.init()
+
+local old_logger = Logging.logger
+
+function Logging.root_logger()
+	return old_logger(root)
+end
+
+function Logging.logger(name)
+	return old_logger( root .. "." .. name )
+end
+
+Init.logger_root = root.."."
+
+
+-- mail  - fix later
+
+Hosting.send_mail = Mail.Sender{
+	host = "smtpcorp.com";
+	username = "smtp@luanhost.com";  -- ?
+	password = "luanhost";
+	port = 2525;
+}.send
+
+
+return Init