comparison src/luan/modules/http/Server.luan @ 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
comparison
equal deleted inserted replaced
1171:794ddcfbee20 1172:1aa6dd74f3fc
28 28
29 local Server = {} 29 local Server = {}
30 30
31 Server.port = 8080 31 Server.port = 8080
32 32
33 function Server.init(dir) 33 local function init_dir(dir)
34 local dir_uri, dir_path 34 local dir_uri, dir_path
35 if matches(dir,":") then 35 if matches(dir,":") then
36 dir_uri = dir 36 dir_uri = dir
37 dir_path = match(dir,"^file:(.*)$") or error "server dir must be scheme 'file:'" 37 dir_path = match(dir,"^file:(.*)$") or error "server dir must be scheme 'file:'"
38 else 38 else
42 dir_uri = gsub(dir_uri,"/$","") -- remove trailing '/' if any 42 dir_uri = gsub(dir_uri,"/$","") -- remove trailing '/' if any
43 Http.dir = dir_uri 43 Http.dir = dir_uri
44 function Io.schemes.site(path) 44 function Io.schemes.site(path)
45 return Io.uri( dir_uri..path ) 45 return Io.uri( dir_uri..path )
46 end 46 end
47 return dir_path
48 end
49
50 function Server.init(dir)
51 local dir_path = init_dir(dir)
47 local file_handler = FileHandler.new(dir_path) 52 local file_handler = FileHandler.new(dir_path)
48 local dir_handler = DirHandler.new(file_handler) 53 local dir_handler = DirHandler.new(file_handler)
49 local luan_handler = LuanHandler.new() 54 local luan_handler = LuanHandler.new()
50 local not_found_hander = NotFound.new(luan_handler) 55 local not_found_hander = NotFound.new(luan_handler)
51 local handler = ListHandler.new( luan_handler, file_handler ) 56 local handler = ListHandler.new( luan_handler, file_handler )
73 Server.init(dir) 78 Server.init(dir)
74 Server.start_rpc() 79 Server.start_rpc()
75 Server.start() 80 Server.start()
76 end 81 end
77 82
83 function Server.serve_for_nginx(dir)
84 init_dir(dir)
85 local luan_handler = LuanHandler.new()
86 local not_found_hander = NotFound.new(luan_handler)
87 local handler = luan_handler
88 handler = IndexHandler.new(handler)
89 handler = ListHandler.new( handler, not_found_hander )
90 handler = ContentTypeHandler.new(handler)
91 handler = SafeHandler.new(handler)
92 handler = LogHandler.new(handler)
93 Server.server = JavaServer.new(Server.port,handler)
94
95 Server.start_rpc()
96 Server.start()
97 end
98
78 return Server 99 return Server