Mercurial Hosting > luan
comparison src/luan/modules/http/Server.luan @ 1256:c147e2e877e3
allow subclassing of HttpServicer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 19 Sep 2018 20:15:16 -0600 |
parents | e55a0c3696fb |
children | 3f4644246e39 |
comparison
equal
deleted
inserted
replaced
1255:4f571a974132 | 1256:c147e2e877e3 |
---|---|
28 | 28 |
29 | 29 |
30 local Server = {} | 30 local Server = {} |
31 | 31 |
32 function Server.init_dir(dir) | 32 function Server.init_dir(dir) |
33 local dir_uri, dir_path | 33 if not matches(dir,":") then |
34 if matches(dir,":") then | 34 dir = "file:"..dir |
35 dir_uri = dir | |
36 dir_path = match(dir,"^file:(.*)$") or error "server dir must be scheme 'file:'" | |
37 else | |
38 dir_path = dir | |
39 dir_uri = "file:"..dir | |
40 end | 35 end |
41 dir_uri = gsub(dir_uri,"/$","") -- remove trailing '/' if any | 36 dir = gsub(dir,"/$","") -- remove trailing '/' if any |
42 Http.dir = dir_uri | 37 Http.dir = dir |
43 function Io.schemes.site(path) | 38 function Io.schemes.site(path) |
44 return Io.uri( dir_uri..path ) | 39 return Io.uri( dir..path ) |
45 end | 40 end |
46 return dir_path | |
47 end | 41 end |
48 | 42 |
49 function Server.start() | 43 function Server.start() |
50 try { | 44 try { |
51 function() | 45 function() |
66 Thread.fork(Rpc.serve) | 60 Thread.fork(Rpc.serve) |
67 end | 61 end |
68 | 62 |
69 function Server.serve(dir,port) | 63 function Server.serve(dir,port) |
70 port = port or 8080 | 64 port = port or 8080 |
71 local dir_path = Server.init_dir(dir) | 65 Server.init_dir(dir) |
66 local dir_path = match(Http.dir,"^file:(.*)$") or error "server dir must be scheme 'file:'" | |
72 local file_handler = FileHandler.new(dir_path) | 67 local file_handler = FileHandler.new(dir_path) |
73 local dir_handler = DirHandler.new(file_handler) | 68 local dir_handler = DirHandler.new(file_handler) |
74 local luan_handler = LuanHandler.new() | 69 local luan_handler = LuanHandler.new() |
75 local not_found_hander = NotFound.new(luan_handler) | 70 local not_found_hander = NotFound.new(luan_handler) |
76 local handler = ListHandler.new( file_handler, luan_handler ) | 71 local handler = ListHandler.new( file_handler, luan_handler ) |