Mercurial Hosting > luan
comparison src/luan/modules/http/Server.luan @ 1315:5763597ca5c0
add DomainHandler
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 30 Jan 2019 01:21:49 -0700 |
parents | 51a1987b55a3 |
children | 643cf1c37723 |
comparison
equal
deleted
inserted
replaced
1314:51a1987b55a3 | 1315:5763597ca5c0 |
---|---|
4 local gsub = String.gsub or error() | 4 local gsub = String.gsub or error() |
5 local match = String.match or error() | 5 local match = String.match or error() |
6 local matches = String.matches or error() | 6 local matches = String.matches or error() |
7 local try = Luan.try or error() | 7 local try = Luan.try or error() |
8 local Io = require "luan:Io.luan" | 8 local Io = require "luan:Io.luan" |
9 local uri = Io.uri or error() | |
9 local Package = require "luan:Package.luan" | 10 local Package = require "luan:Package.luan" |
10 local Rpc = require "luan:Rpc.luan" | 11 local Rpc = require "luan:Rpc.luan" |
11 local Thread = require "luan:Thread.luan" | 12 local Thread = require "luan:Thread.luan" |
12 local Http = require "luan:http/Http.luan" | 13 local Http = require "luan:http/Http.luan" |
13 local Logging = require "luan:logging/Logging.luan" | 14 local Logging = require "luan:logging/Logging.luan" |
33 dir = "file:"..dir | 34 dir = "file:"..dir |
34 end | 35 end |
35 dir = gsub(dir,"/$","") -- remove trailing '/' if any | 36 dir = gsub(dir,"/$","") -- remove trailing '/' if any |
36 Http.dir = dir | 37 Http.dir = dir |
37 function Io.schemes.site(path) | 38 function Io.schemes.site(path) |
38 return Io.uri( dir..path ) | 39 return uri( dir..path ) |
39 end | 40 end |
40 end | 41 end |
41 | 42 |
42 local function start(server) | 43 local function start(server) |
43 try { | 44 try { |
75 local server = JavaServer.new(port,handler) | 76 local server = JavaServer.new(port,handler) |
76 start(server) | 77 start(server) |
77 return server, luan_handler | 78 return server, luan_handler |
78 end | 79 end |
79 | 80 |
80 function Server.serve_for_proxy(dir,port) | 81 function Server.serve_for_proxy(dir,port,LuanHandlerClass) |
81 port = port or 8080 | 82 port = port or 8080 |
83 LuanHandlerClass = LuanHandlerClass or LuanHandler | |
82 Server.init_dir(dir) | 84 Server.init_dir(dir) |
83 local luan_handler = LuanHandler.new() | 85 local luan_handler = LuanHandlerClass.new() |
84 local handler = IndexHandler.new(luan_handler) | 86 local handler = IndexHandler.new(luan_handler) |
85 handler = ContentTypeHandler.new(handler) | 87 handler = ContentTypeHandler.new(handler) |
86 handler = SafeHandler.new(handler) | 88 handler = SafeHandler.new(handler) |
87 local server = JavaServer.new(port,handler) | 89 local server = JavaServer.new(port,handler) |
88 start(server) | 90 start(server) |