view conf/serve_nabble.luan @ 44:cc5b7d515580

remove post by email
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Jun 2021 09:43:51 -0600
parents abe0694e9849
children
line wrap: on
line source

java()
local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local Io = require "luan:Io.luan"
local String = require "luan:String.luan"
local LoggerFactory = require "java:org.slf4j.LoggerFactory"
local Log4j = require "java:nabble.utils.Log4j"
local Init = require "file:conf/Init.luan"


local Serve = {}

Serve.username = "nabble"
Serve.password = "password"

Serve.is_www = false
Serve.is_forums = true

Serve.www_port = 8080
Serve.forums_port = 8080

local log_to_console = false

for _, arg in ipairs{...} do
	if arg == "console" then
		log_to_console = true
	end
	if arg == "www" then
		Serve.is_www = true
	end
end

Init.fix_serve(Serve)

if log_to_console then
	Log4j.initForConsole()
else
	Log4j.initBasicFiles("logs/info.log", "logs/warn.log", "logs/error.log", "5MB")
	Log4j.initForClass("nabble.view.web.embed.JsEmbed", "logs/embed.log", "1MB")
end

local logger = LoggerFactory.getLogger("serve_nabble");

local function add_contexts(jetty)
	local context = jetty.newTools2Context()
	jetty.authenticate(context, "/*", Serve.username, Serve.password)
	
	-- /logs folder
	context = jetty.newFolderContext("/logs", "logs", { "/*" }, true);
	jetty.authenticate(context, "/*", Serve.username, Serve.password)
	
	-- /conf folder
	context = jetty.newFolderContext("/conf", "conf", { "/*" }, true);
	jetty.authenticate(context, "/*", Serve.username, Serve.password)
end


if Serve.is_www then

	-- jetty

	local GlobalJetty = require "java:global.GlobalJetty"
	
	local jetty = GlobalJetty.new();
	local context = jetty.newWebContext();
	
	jetty.authenticate(context, "/tools/*", Serve.username, Serve.password)
	
	add_contexts(jetty)
	
	-- /html folder
	context = jetty.newFolderContext("/html", "html", { "/*" }, true);
	jetty.authenticate(context,"/*", Serve.username, Serve.password);
	
	local log = jetty.newNCSARequestLog()
	local server = jetty.newServer(Serve.www_port, log);
	server.start();
	
	logger.error("www server started");
end


if Serve.is_forums then
	local Jetty = require "java:nabble.utils.Jetty"
	
	local jettyConfig = {
		cache = "true"
		timeLimit = "60000"
		errorCacheSize = "1000"
		ipListSize = "5"
		exportDir = "export/"
	}
	
	local jetty = Jetty.new();
	local context = jetty.newWebContext(jettyConfig);
	
	context.setMaxFormContentSize(500000);
	jetty.authenticate(context, "/tools/*", Serve.username, Serve.password);
	
	
	-- Start Filters
	
	Init.add_filters(context)

	jetty.addNabbleErrorFilter(context);
	
	jetty.addNabbleConnectionLimitFilter(context, { max = "115", queueSize = "1000", timeoutDelay = "45000" });
	
	jetty.addBadBotFilter(context, { max = "10" });
	
	jetty.addCachingFilter(context, { dir = Init.home_dir.."local/cache", hasDelayedDelete = "true", acceptEncoding = "gzip" });
	local FileHandler = require "java:cachingfilter.FileHandler"
	FileHandler.factory = FileHandler.mappedOrIoFile;
	
	jetty.addGzipFilter(context);
	
	add_contexts(jetty)
	
	-- /backups folder
	context = jetty.newFolderContext("/backups", Init.home_dir.."local/schemas", { "/*" }, false);
	
	local log
	if log_to_console then
		log = jetty.newNCSARequestLog()
	else
		Io.uri("file:logs/daily").mkdir()
		log = jetty.newNCSARequestLog("logs/daily/yyyy_mm_dd.log")
		log.setRetainDays(30)
	end
	
	local server = jetty.newServer(Serve.forums_port, log);
	jetty.setThreadPool(server);

	local DbGlobalUpdater = require "java:nabble.model.DbGlobalUpdater"
	DbGlobalUpdater.updateGlobal()
	logger.info "db update done"

	local ClearCache = require "java:nabble.view.lib.ClearCache"
	ClearCache.run()
	--logger.info "db cache cleared"

	server.start();
	
	logger.error("nabble server started");
	
	jetty.addShutdownHook(server);
end_if