feat(core): implement file-based API versioning system (DAW/furt#83)
- Add VERSION file in repository root - Add read_version() function with error handling - Update /health endpoint to show file-based version - Add version display during server startup - Fallback to ?.?.? when VERSION file unreadable Enables deployment tracking across dev/test/prod environments
This commit is contained in:
parent
5b851b8bfb
commit
7053af3c0d
2 changed files with 52 additions and 28 deletions
1
VERSION
Normal file
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
0.1.1
|
||||||
27
src/main.lua
27
src/main.lua
|
|
@ -13,6 +13,25 @@ local AuthRoute = require("src.routes.auth")
|
||||||
-- Load configuration
|
-- Load configuration
|
||||||
local config = require("config.server")
|
local config = require("config.server")
|
||||||
|
|
||||||
|
-- Read version from VERSION file
|
||||||
|
local function read_version()
|
||||||
|
local file, err = io.open("VERSION", "r")
|
||||||
|
if not file then
|
||||||
|
print("WARNING: Could not read VERSION file: " .. (err or "unknown error"))
|
||||||
|
return "?.?.?"
|
||||||
|
end
|
||||||
|
|
||||||
|
local version = file:read("*line")
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
if not version or version:match("^%s*$") then
|
||||||
|
print("WARNING: VERSION file is empty or contains only whitespace")
|
||||||
|
return "?.?.?"
|
||||||
|
end
|
||||||
|
|
||||||
|
return version:match("^%s*(.-)%s*$") -- trim whitespace
|
||||||
|
end
|
||||||
|
|
||||||
-- HTTP-Server Module
|
-- HTTP-Server Module
|
||||||
local FurtServer = {}
|
local FurtServer = {}
|
||||||
|
|
||||||
|
|
@ -224,7 +243,10 @@ function FurtServer:start()
|
||||||
error("Failed to bind to " .. self.host .. ":" .. self.port)
|
error("Failed to bind to " .. self.host .. ":" .. self.port)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local version = read_version()
|
||||||
|
|
||||||
print(string.format("Furt HTTP-Server started on %s:%d", self.host, self.port))
|
print(string.format("Furt HTTP-Server started on %s:%d", self.host, self.port))
|
||||||
|
print("Version: " .. version)
|
||||||
print("API-Key authentication: ENABLED")
|
print("API-Key authentication: ENABLED")
|
||||||
print("Rate limiting: ENABLED (60 req/hour per API key, 100 req/hour per IP)")
|
print("Rate limiting: ENABLED (60 req/hour per API key, 100 req/hour per IP)")
|
||||||
print("CORS enabled for configured origins")
|
print("CORS enabled for configured origins")
|
||||||
|
|
@ -245,10 +267,11 @@ local server = FurtServer:new()
|
||||||
|
|
||||||
-- Public routes (no authentication required)
|
-- Public routes (no authentication required)
|
||||||
server:add_route("GET", "/health", function(request, server)
|
server:add_route("GET", "/health", function(request, server)
|
||||||
|
local version = read_version()
|
||||||
local response_data = {
|
local response_data = {
|
||||||
status = "healthy",
|
status = "healthy",
|
||||||
service = "furt-lua",
|
service = "furt-lua",
|
||||||
version = "1.1.0",
|
version = version,
|
||||||
timestamp = os.time(),
|
timestamp = os.time(),
|
||||||
features = {
|
features = {
|
||||||
smtp_configured = config.mail and config.mail.username ~= nil,
|
smtp_configured = config.mail and config.mail.username ~= nil,
|
||||||
|
|
@ -276,7 +299,7 @@ if os.getenv("ENABLE_TEST_ENDPOINT") == "true" then
|
||||||
|
|
||||||
return server:create_response(200, response_data, nil, nil, request)
|
return server:create_response(200, response_data, nil, nil, request)
|
||||||
end)
|
end)
|
||||||
print("⚠️ Test endpoint enabled (development mode)")
|
print("[WARN] Test endpoint enabled (development mode)")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Protected routes (require authentication)
|
-- Protected routes (require authentication)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue