- Extract health routes to src/routes/health.lua (80 lines) - Extract HTTP server core to src/http_server.lua (256 lines) - Reduce main.lua to pure orchestration (342 → 27 lines) - Preserve all functionality and API compatibility - Add proper module separation following existing patterns - Enable future service self-registration architecture Closes #96
80 lines
2.5 KiB
Lua
80 lines
2.5 KiB
Lua
-- src/routes/health.lua
|
|
-- Health monitoring and diagnostic routes for Furt API-Gateway
|
|
-- Dragons@Work Digital Sovereignty Project
|
|
|
|
local found_cjson, cjson = pcall(require, 'cjson')
|
|
if not found_cjson then
|
|
cjson = require('dkjson')
|
|
end
|
|
|
|
local config = require("config.server")
|
|
|
|
local HealthRoute = {}
|
|
|
|
-- Get version information from merkwerk integration
|
|
function HealthRoute.get_version_info()
|
|
-- Load merkwerk integration
|
|
local success, merkwerk = pcall(require, "integrations.lua-api")
|
|
if not success then
|
|
print("WARNING: merkwerk integration not available, using fallback")
|
|
return {
|
|
service = "furt-lua",
|
|
version = "?.?.?",
|
|
content_hash = "unknown",
|
|
vcs_info = { type = "none", hash = "", branch = "" },
|
|
source = "fallback-no-merkwerk"
|
|
}
|
|
end
|
|
|
|
-- Get merkwerk health info
|
|
local health_info = merkwerk.get_health_info()
|
|
|
|
-- Ensure compatibility with old VERSION-only expectations
|
|
if not health_info.version then
|
|
health_info.version = "?.?.?"
|
|
end
|
|
|
|
return health_info
|
|
end
|
|
|
|
-- Handle /health endpoint - system health check
|
|
function HealthRoute.handle_health(request, server)
|
|
local version_info = HealthRoute.get_version_info()
|
|
local response_data = {
|
|
status = "healthy",
|
|
service = version_info.service or "furt-lua",
|
|
version = version_info.version,
|
|
content_hash = version_info.content_hash,
|
|
vcs_info = version_info.vcs_info,
|
|
timestamp = os.time(),
|
|
source = version_info.source,
|
|
features = {
|
|
smtp_configured = config.smtp_default and config.smtp_default.host ~= nil,
|
|
auth_enabled = true,
|
|
rate_limiting = true,
|
|
rate_limits = config.security and config.security.rate_limits,
|
|
merkwerk_integrated = version_info.source == "merkwerk"
|
|
}
|
|
}
|
|
return server:create_response(200, response_data, nil, nil, request)
|
|
end
|
|
|
|
-- Handle /test endpoint - development testing (configurable)
|
|
function HealthRoute.handle_test(request, server)
|
|
local response_data = {
|
|
message = "Test endpoint working",
|
|
received_data = request.body,
|
|
headers_count = 0,
|
|
warning = "This is a development endpoint (enabled via config)"
|
|
}
|
|
|
|
-- Count headers
|
|
for _ in pairs(request.headers) do
|
|
response_data.headers_count = response_data.headers_count + 1
|
|
end
|
|
|
|
return server:create_response(200, response_data, nil, nil, request)
|
|
end
|
|
|
|
return HealthRoute
|
|
|