Mercurial Hosting > luan
annotate src/luan/host/Init.luan @ 1315:5763597ca5c0
add DomainHandler
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 30 Jan 2019 01:21:49 -0700 |
parents | 60d013d5c7ef |
children | 307e76ccd0d6 |
rev | line source |
---|---|
1135 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
1238 | 3 local do_file = Luan.do_file or error() |
1135 | 4 local String = require "luan:String.luan" |
5 local gsub = String.gsub or error() | |
6 | |
7 | |
8 local Init = {} | |
9 | |
10 local dir, domain = ... | |
11 | |
12 | |
13 -- logging | |
14 | |
15 java() | |
16 local Logger = require "java:org.apache.log4j.Logger" | |
1199 | 17 local Level = require "java:org.apache.log4j.Level" |
18 local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" | |
19 local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" | |
1135 | 20 |
21 local root = gsub(domain,"\.",":") | |
22 | |
1199 | 23 local logger = Logger.getLogger(root) |
24 local has_appenders = logger.getAllAppenders().hasMoreElements() | |
25 if not has_appenders then | |
26 logger.setAdditivity(false) | |
27 local layout = EnhancedPatternLayout.new("%d %-5p %c{-1} - %m%n") | |
28 local log_dir = dir.."/site/private/local/logs/" | |
1135 | 29 |
1199 | 30 local function add_appender(file,level) |
31 local appender = RollingFileAppender.new(layout, log_dir..file) | |
32 appender.setMaxFileSize("1MB") | |
33 logger.addAppender(appender) | |
34 if level ~= logger.getEffectiveLevel() then | |
35 appender.setThreshold(level) | |
36 end | |
37 end | |
1135 | 38 |
1199 | 39 add_appender("error.log",Level.ERROR) |
40 add_appender("warn.log",Level.WARN) | |
41 add_appender("info.log",Level.INFO) | |
1135 | 42 end |
43 | |
1199 | 44 local Logging = require "luan:logging/Logging.luan" |
1135 | 45 |
46 local old_logger = Logging.logger | |
1239
2612e4307987
minor luanhost logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1238
diff
changeset
|
47 Logging.luanhost_logger = old_logger |
1135 | 48 |
49 function Logging.root_logger() | |
50 return old_logger(root) | |
51 end | |
52 | |
53 function Logging.logger(name) | |
54 return old_logger( root .. "." .. name ) | |
55 end | |
56 | |
57 Init.logger_root = root.."." | |
58 | |
59 | |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
60 -- set vars |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
61 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
62 local Io = require "luan:Io.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
63 local Http = require "luan:http/Http.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
64 local Hosting = require "luan:host/Hosting.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
65 local Mail = require "luan:mail/Mail.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
66 |
1238 | 67 Init.password = do_file(dir.."/info.luan").password or error() |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
68 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
69 Http.dir = "file:"..dir.."/site" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
70 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
71 function Io.schemes.site(path,loading) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
72 return Io.uri( Http.dir..path, loading ) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
73 end |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
74 |
1315 | 75 Http.domain = domain |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
76 Io.password = Init.password |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
77 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
78 |
1135 | 79 -- mail - fix later |
80 | |
81 Hosting.send_mail = Mail.Sender{ | |
1312 | 82 host = "smtpcorp.com" |
83 username = "smtp@luan.ws" -- ? | |
84 password = "luanhost" | |
85 port = 2525 | |
1135 | 86 }.send |
87 | |
88 | |
1238 | 89 -- callback to luanhost code |
90 do_file "file:init.luan" | |
91 | |
92 | |
1135 | 93 return Init |