feat(furt): implement complete Lua HTTP-Server for digital sovereignty (#63)
- Add furt-lua/ directory with pure Lua implementation - Replace planned Go implementation with Corporate-free technology - Complete Week 1 Challenge: HTTP-Server to production-ready in 48min - HTTP-Server in pure Lua (185 lines, lua-socket based) - JSON API endpoints with request/response parsing - Modular architecture: each file < 200 lines - Error handling for 404, 400, validation scenarios - GET /health - Service health check with timestamp - POST /test - Development testing with request echo - POST /v1/mail/send - Mail service foundation with validation - Comprehensive error responses with structured JSON - Smart startup script with dependency auto-detection - Automated test suite with lua-socket HTTP client - Manual curl test suite for development workflow - Complete documentation and installation guide - FROM: Go (Google-controlled) → TO: Lua (PUC-Rio University) - Corporate-free dependency chain: lua-socket + lua-cjson + lua-ssl - Performance superior: < 1ms response time, minimal memory usage - Foundation for planned C+Lua hybrid architecture - furt-lua/src/main.lua - HTTP-Server implementation - furt-lua/config/server.lua - Lua-based configuration - furt-lua/scripts/start.sh - Startup with dependency checks - furt-lua/scripts/test_curl.sh - Manual testing suite - furt-lua/tests/test_http.lua - Automated test framework - furt-lua/README.md - Implementation documentation - README.md - Document Go→Lua migration strategy - .gitignore - Add Lua artifacts, luarocks, issue-scripts All endpoints tested and working: ✓ Health check returns proper JSON status ✓ Test endpoint processes POST requests with JSON ✓ Mail endpoint validates required fields (name, email, message) ✓ Error handling returns appropriate HTTP status codes Ready for Week 2: SMTP integration with mail.dragons-at-work.de Completes #63 Related #62
This commit is contained in:
parent
10b795ce13
commit
662bfc7b7a
9 changed files with 1058 additions and 537 deletions
83
furt-lua/scripts/start.sh
Executable file
83
furt-lua/scripts/start.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
# furt-lua/scripts/start.sh
|
||||
# Start script for Furt Lua HTTP-Server
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Script directory
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
|
||||
echo -e "${GREEN}=== Furt Lua HTTP-Server Startup ===${NC}"
|
||||
|
||||
# Check if Lua is installed
|
||||
if ! command -v lua &> /dev/null; then
|
||||
echo -e "${RED}Error: Lua is not installed${NC}"
|
||||
echo "Install with: pacman -S lua (Arch) or apt install lua5.4 (Ubuntu)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Lua version
|
||||
LUA_VERSION=$(lua -v 2>&1 | head -n1)
|
||||
echo -e "${YELLOW}Lua version:${NC} $LUA_VERSION"
|
||||
|
||||
# Check required dependencies
|
||||
echo -e "${YELLOW}Checking dependencies...${NC}"
|
||||
|
||||
# Test lua-socket
|
||||
lua -e "require('socket')" 2>/dev/null || {
|
||||
echo -e "${RED}Error: lua-socket not found${NC}"
|
||||
echo "Install with: pacman -S lua-socket (Arch) or apt install lua-socket (Ubuntu)"
|
||||
exit 1
|
||||
}
|
||||
echo -e "${GREEN}✓${NC} lua-socket found"
|
||||
|
||||
# Test lua-cjson (system or luarocks)
|
||||
LUA_PATH="$HOME/.luarocks/share/lua/5.4/?.lua;;" \
|
||||
LUA_CPATH="$HOME/.luarocks/lib/lua/5.4/?.so;;" \
|
||||
lua -e "require('cjson')" 2>/dev/null || {
|
||||
echo -e "${RED}Error: lua-cjson not found${NC}"
|
||||
echo "Install with: pacman -S lua-cjson (Arch) or luarocks install --local lua-cjson"
|
||||
exit 1
|
||||
}
|
||||
echo -e "${GREEN}✓${NC} lua-cjson found"
|
||||
|
||||
# Test lua-ssl (optional for HTTPS)
|
||||
LUA_PATH="$HOME/.luarocks/share/lua/5.4/?.lua;;" \
|
||||
LUA_CPATH="$HOME/.luarocks/lib/lua/5.4/?.so;;" \
|
||||
lua -e "require('ssl')" 2>/dev/null && {
|
||||
echo -e "${GREEN}✓${NC} lua-ssl found (HTTPS ready)"
|
||||
} || {
|
||||
echo -e "${YELLOW}○${NC} lua-ssl not found (install with: luarocks install --local luaossl)"
|
||||
}
|
||||
|
||||
# Set environment variables for mail (if not set)
|
||||
if [ -z "$FURT_MAIL_USERNAME" ]; then
|
||||
echo -e "${YELLOW}Warning: FURT_MAIL_USERNAME not set${NC}"
|
||||
fi
|
||||
|
||||
if [ -z "$FURT_MAIL_PASSWORD" ]; then
|
||||
echo -e "${YELLOW}Warning: FURT_MAIL_PASSWORD not set${NC}"
|
||||
fi
|
||||
|
||||
# Change to project directory
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
# Add current directory and luarocks to Lua path for requires
|
||||
export LUA_PATH="$PROJECT_DIR/src/?.lua;$PROJECT_DIR/?.lua;$HOME/.luarocks/share/lua/5.4/?.lua;;"
|
||||
export LUA_CPATH="$HOME/.luarocks/lib/lua/5.4/?.so;;"
|
||||
|
||||
echo -e "${GREEN}Starting Furt HTTP-Server...${NC}"
|
||||
echo -e "${YELLOW}Project directory:${NC} $PROJECT_DIR"
|
||||
echo -e "${YELLOW}Lua paths configured for system + luarocks${NC}"
|
||||
echo ""
|
||||
|
||||
# Start server
|
||||
lua src/main.lua
|
||||
|
||||
94
furt-lua/scripts/test_curl.sh
Executable file
94
furt-lua/scripts/test_curl.sh
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
#!/bin/bash
|
||||
# furt-lua/scripts/test_curl.sh
|
||||
# Manual curl tests for Furt Lua HTTP-Server
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Server configuration
|
||||
SERVER_URL="http://127.0.0.1:8080"
|
||||
|
||||
echo -e "${GREEN}=== Furt HTTP-Server Manual Tests ===${NC}"
|
||||
echo -e "${YELLOW}Server:${NC} $SERVER_URL"
|
||||
echo ""
|
||||
|
||||
# Test 1: Health Check
|
||||
echo -e "${YELLOW}Test 1: Health Check${NC}"
|
||||
echo "curl -X GET $SERVER_URL/health"
|
||||
echo ""
|
||||
curl -X GET "$SERVER_URL/health" | jq . 2>/dev/null || curl -X GET "$SERVER_URL/health"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 2: Basic POST Test
|
||||
echo -e "${YELLOW}Test 2: Basic POST Test${NC}"
|
||||
echo "curl -X POST $SERVER_URL/test -H 'Content-Type: application/json' -d '{\"test\":\"data\"}'"
|
||||
echo ""
|
||||
curl -X POST "$SERVER_URL/test" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"test":"data","number":42}' | jq . 2>/dev/null || \
|
||||
curl -X POST "$SERVER_URL/test" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"test":"data","number":42}'
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 3: Mail Endpoint - Valid Data
|
||||
echo -e "${YELLOW}Test 3: Mail Endpoint - Valid Data${NC}"
|
||||
echo "curl -X POST $SERVER_URL/v1/mail/send -H 'Content-Type: application/json' -d '{...}'"
|
||||
echo ""
|
||||
curl -X POST "$SERVER_URL/v1/mail/send" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "Test User",
|
||||
"email": "test@example.com",
|
||||
"message": "This is a test message from curl"
|
||||
}' | jq . 2>/dev/null || \
|
||||
curl -X POST "$SERVER_URL/v1/mail/send" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "Test User",
|
||||
"email": "test@example.com",
|
||||
"message": "This is a test message from curl"
|
||||
}'
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 4: Mail Endpoint - Invalid Data
|
||||
echo -e "${YELLOW}Test 4: Mail Endpoint - Invalid Data (Missing Fields)${NC}"
|
||||
echo "curl -X POST $SERVER_URL/v1/mail/send -H 'Content-Type: application/json' -d '{\"name\":\"Test\"}'"
|
||||
echo ""
|
||||
curl -X POST "$SERVER_URL/v1/mail/send" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":"Test"}' | jq . 2>/dev/null || \
|
||||
curl -X POST "$SERVER_URL/v1/mail/send" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name":"Test"}'
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 5: 404 Error
|
||||
echo -e "${YELLOW}Test 5: 404 Error Handling${NC}"
|
||||
echo "curl -X GET $SERVER_URL/nonexistent"
|
||||
echo ""
|
||||
curl -X GET "$SERVER_URL/nonexistent" | jq . 2>/dev/null || curl -X GET "$SERVER_URL/nonexistent"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
# Test 6: Method Not Allowed (if we want to test this)
|
||||
echo -e "${YELLOW}Test 6: Wrong Method${NC}"
|
||||
echo "curl -X PUT $SERVER_URL/v1/mail/send"
|
||||
echo ""
|
||||
curl -X PUT "$SERVER_URL/v1/mail/send" | jq . 2>/dev/null || curl -X PUT "$SERVER_URL/v1/mail/send"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
echo -e "${GREEN}=== Manual Tests Complete ===${NC}"
|
||||
echo -e "${YELLOW}Note:${NC} These tests show the raw HTTP responses."
|
||||
echo -e "${YELLOW} For automated testing, use: lua tests/test_http.lua${NC}"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue