view src/luan/host/run.luan @ 1598:c78d6a4e2d9a

web logging
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Apr 2021 15:09:51 -0600
parents 732b5de211fc
children bd125ee375d2
line wrap: on
line source
require "java"
local Luan = require "luan:Luan.luan"
local error = Luan.error
local do_file = Luan.do_file or error()
local ipairs = Luan.ipairs or error()
local Io = require "luan:Io.luan"
local Hosted = require "luan:host/Hosted.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "run"
local WebHandler = require "java:luan.host.WebHandler"
Hosted.WebHandler = WebHandler


local here = Io.schemes.file(".").canonical().to_string()
Hosted.sites_dir = here.."/sites/"

do_file "classpath:luan/host/main.luan"


-- web server

local Server = require "java:goodjava.webserver.Server"

local handler = WebHandler.new(Hosted.sites_dir)
local server = Server.ForAddress.new("127.0.0.1",8080,handler)
server.start()


local sites_dir = Io.schemes.file(Hosted.sites_dir)
for _, site_dir in ipairs(sites_dir.children()) do
	local name = site_dir.name()
	WebHandler.loadHandler(name)
end