Mercurial Hosting > luan
comparison src/luan/modules/http/impl/Server.luan @ 1162:e2d2354807f3
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 06 Feb 2018 21:25:55 -0700 |
parents | 4beabb087be6 |
children | 7e6f28c769a1 |
comparison
equal
deleted
inserted
replaced
1161:6baccd0c85a7 | 1162:e2d2354807f3 |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local String = require "luan:String.luan" | 3 local String = require "luan:String.luan" |
4 local gsub = String.gsub or error() | 4 local gsub = String.gsub or error() |
5 local match = String.match or error() | |
5 local matches = String.matches or error() | 6 local matches = String.matches or error() |
6 local Io = require "luan:Io.luan" | 7 local Io = require "luan:Io.luan" |
7 local Package = require "luan:Package.luan" | 8 local Package = require "luan:Package.luan" |
8 local Rpc = require "luan:Rpc.luan" | 9 local Rpc = require "luan:Rpc.luan" |
9 local Thread = require "luan:Thread.luan" | 10 local Thread = require "luan:Thread.luan" |
27 local Server = {} | 28 local Server = {} |
28 | 29 |
29 Server.port = 8080 | 30 Server.port = 8080 |
30 | 31 |
31 function Server.init(dir) | 32 function Server.init(dir) |
32 matches(dir,"^file:") or error "server dir must be scheme 'file:'" | 33 local dir_uri, dir_path |
33 dir = gsub(dir,"/$","") -- remove trailing '/' if any | 34 if matches(dir,":") then |
34 -- Http.dir = 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 | |
41 dir_uri = gsub(dir_uri,"/$","") -- remove trailing '/' if any | |
42 -- Http.dir = dir_uri | |
35 function Io.schemes.site(path) | 43 function Io.schemes.site(path) |
36 return Io.uri( dir..path ) | 44 return Io.uri( dir_uri..path ) |
37 end | 45 end |
38 local file_dir = Io.uri(dir).to_string() | 46 local handler = FileHandler.new(dir_path) |
39 local handler = FileHandler.new(file_dir) | |
40 local luan_handler = LuanHandler.new() | 47 local luan_handler = LuanHandler.new() |
41 handler = ListHandler.new( luan_handler, handler ) | 48 handler = ListHandler.new( luan_handler, handler ) |
42 handler = IndexHandler.new(handler) | 49 handler = IndexHandler.new(handler) |
43 handler = NotFound.new(handler) | 50 handler = NotFound.new(handler) |
44 handler = ContentTypeHandler.new(handler) | 51 handler = ContentTypeHandler.new(handler) |