comparison 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
comparison
equal deleted inserted replaced
1184:2eba58842bbb 1185:94cf2576a922
1 local Package = require "luan:Package.luan"
2 Package.loaded["luan:http/Http.luan"] = require "luan:http/jetty/Http.luan"
3
4 local Luan = require "luan:Luan.luan"
5 local error = Luan.error
6 local String = require "luan:String.luan"
7 local gsub = String.gsub or error()
8 local Io = require "luan:Io.luan"
9 local Http = require "luan:http/Http.luan"
10 local Hosting = require "luan:host/Hosting.luan"
11 local Mail = require "luan:mail/Mail.luan"
12
13
14 local Init = {}
15
16 local dir, domain = ...
17
18 Init.password = Luan.do_file(dir.."/info.luan").password or error()
19
20 Http.dir = "file:"..dir.."/site"
21
22 function Io.schemes.site(path,loading)
23 return Io.uri( Http.dir..path, loading )
24 end
25
26 Hosting.domain = domain
27 Io.password = Init.password
28
29
30 -- logging
31
32 java()
33 local Logger = require "java:org.apache.log4j.Logger"
34 local Logging = require "luan:logging/Logging.luan"
35
36 local root = gsub(domain,"\.",":")
37
38 Logging.layout = "%d %-5p %c{-1} - %m%n"
39 Logging.file = dir.."/site/private/local/logs/luan.log"
40 Logging.max_file_size = "1MB"
41 local one_mb = 1048576
42
43 local log_dir = dir.."/site/private/local/logs/"
44 Logging.appenders = {
45 [log_dir.."error.log"] = "ERROR"
46 [log_dir.."warn.log"] = "WARN"
47 [log_dir.."info.log"] = "INFO"
48 }
49
50 Logging.log4j_root_logger = Logger.getLogger(root)
51 Logging.log4j_root_logger.setAdditivity(false)
52
53 local old_log_to_file = Logging.log_to_file
54
55 function Logging.log_to_file(file,logger_name)
56 Io.schemes.file(file) -- security check
57 logger_name = logger_name and root .. "." .. logger_name
58 local appender = old_log_to_file(file,logger_name)
59 appender.getMaximumFileSize() <= one_mb or error "Logging.max_file_size is too big"
60 return appender
61 end
62
63 local old_init = Logging.init
64
65 function Logging.init()
66 Logging.appenders["System.err"] = nil
67 Logging.appenders["System.out"] = nil
68 old_init()
69 end
70
71 Logging.init()
72
73 local old_logger = Logging.logger
74
75 function Logging.root_logger()
76 return old_logger(root)
77 end
78
79 function Logging.logger(name)
80 return old_logger( root .. "." .. name )
81 end
82
83 Init.logger_root = root.."."
84
85
86 -- mail - fix later
87
88 Hosting.send_mail = Mail.Sender{
89 host = "smtpcorp.com";
90 username = "smtp@luanhost.com"; -- ?
91 password = "luanhost";
92 port = 2525;
93 }.send
94
95
96 return Init