Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/modules/http/impl/Server.luan Mon Feb 05 22:59:52 2018 -0700 +++ b/src/luan/modules/http/impl/Server.luan Tue Feb 06 21:25:55 2018 -0700 @@ -2,6 +2,7 @@ local error = Luan.error local String = require "luan:String.luan" local gsub = String.gsub or error() +local match = String.match or error() local matches = String.matches or error() local Io = require "luan:Io.luan" local Package = require "luan:Package.luan" @@ -29,14 +30,20 @@ Server.port = 8080 function Server.init(dir) - matches(dir,"^file:") or error "server dir must be scheme 'file:'" - dir = gsub(dir,"/$","") -- remove trailing '/' if any --- Http.dir = dir + local dir_uri, dir_path + if matches(dir,":") then + dir_uri = dir + dir_path = match(dir,"^file:(.*)$") or error "server dir must be scheme 'file:'" + else + dir_path = dir + dir_uri = "file:"..dir + end + dir_uri = gsub(dir_uri,"/$","") -- remove trailing '/' if any +-- Http.dir = dir_uri function Io.schemes.site(path) - return Io.uri( dir..path ) + return Io.uri( dir_uri..path ) end - local file_dir = Io.uri(dir).to_string() - local handler = FileHandler.new(file_dir) + local handler = FileHandler.new(dir_path) local luan_handler = LuanHandler.new() handler = ListHandler.new( luan_handler, handler ) handler = IndexHandler.new(handler)