- nginx-style furt.conf configuration - Multi-tenant mail routing per API key - Custom SMTP support per customer - Backward compatibility via server.lua adapter WIP: Ready for testing on werner
79 lines
2.7 KiB
Lua
79 lines
2.7 KiB
Lua
-- config/server.lua
|
|
-- Multi-Tenant server configuration using nginx-style config parser
|
|
-- Dragons@Work Digital Sovereignty Project
|
|
|
|
local ConfigParser = require("src.config_parser")
|
|
|
|
-- Load configuration from furt.conf
|
|
local config = ConfigParser.load_config()
|
|
|
|
-- Add legacy compatibility and runtime enhancements
|
|
local server_config = {
|
|
-- HTTP Server settings (from [server] section)
|
|
host = config.server.host,
|
|
port = config.server.port,
|
|
|
|
-- Timeouts and limits
|
|
client_timeout = config.server.client_timeout or 10,
|
|
|
|
-- CORS Configuration
|
|
cors = {
|
|
allowed_origins = (function()
|
|
local env_origins = os.getenv("CORS_ALLOWED_ORIGINS")
|
|
if env_origins then
|
|
-- Parse comma-separated list from environment
|
|
local origins = {}
|
|
for origin in env_origins:gmatch("([^,]+)") do
|
|
table.insert(origins, origin:match("^%s*(.-)%s*$"))
|
|
end
|
|
return origins
|
|
else
|
|
-- Default development origins
|
|
return {
|
|
"http://localhost:1313", -- Hugo dev server
|
|
"http://127.0.0.1:1313", -- Hugo dev server alternative
|
|
"http://localhost:3000", -- Common dev port
|
|
"http://127.0.0.1:3000" -- Common dev port alternative
|
|
}
|
|
end
|
|
end)()
|
|
},
|
|
|
|
-- Logging
|
|
log_level = config.server.log_level or "info",
|
|
log_requests = config.server.log_requests or true,
|
|
|
|
-- API Keys (converted from nginx-style to old format for backward compatibility)
|
|
api_keys = config.api_keys,
|
|
|
|
-- Default SMTP config (for legacy compatibility)
|
|
mail = config.smtp_default,
|
|
|
|
-- Multi-tenant mail configuration function
|
|
get_mail_config_for_api_key = function(api_key)
|
|
return ConfigParser.get_mail_config_for_api_key(config, api_key)
|
|
end,
|
|
|
|
-- Raw config access (for advanced usage)
|
|
raw_config = config
|
|
}
|
|
|
|
-- Print configuration summary on load
|
|
print("Furt Multi-Tenant Configuration Loaded:")
|
|
print(" Server: " .. server_config.host .. ":" .. server_config.port)
|
|
print(" Log Level: " .. server_config.log_level)
|
|
print(" Default SMTP: " .. (config.smtp_default.host or "not configured"))
|
|
|
|
local api_key_count = 0
|
|
for key_name, key_config in pairs(config.api_keys) do
|
|
api_key_count = api_key_count + 1
|
|
local smtp_info = ""
|
|
if key_config.mail_smtp_host then
|
|
smtp_info = " (custom SMTP: " .. key_config.mail_smtp_host .. ")"
|
|
end
|
|
print(" API Key: " .. key_config.name .. " -> " .. key_config.mail_to .. smtp_info)
|
|
end
|
|
print(" Total API Keys: " .. api_key_count)
|
|
|
|
return server_config
|
|
|