Simplify development workflow and fix content editing conflicts

- Replace complex multi-server setup (live-server + API) with unified Go server
- Serve all sites at /sites/{site_id} endpoints, eliminating port conflicts
- Fix content-type middleware to serve proper MIME types for static files
- Prevent script injection duplication with future-proof CDN-compatible detection
- Remove auto page reload from enhance button to eliminate editing interruptions
- Enable seamless content editing workflow with manual enhancement control

Development now requires only 'just dev' instead of complex demo commands.
All sites immediately available at localhost:8080 without hot reload conflicts.
This commit is contained in:
2025-09-16 19:10:57 +02:00
parent eabb7b16e8
commit a3fc3089d2
6 changed files with 90 additions and 160 deletions

185
justfile
View File

@@ -25,171 +25,57 @@ dev: build-lib build
fi
echo ""
echo "📝 Unified logs below (API server + Demo site):"
echo "🔌 [SERVER] = API server logs"
echo "🌐 [DEMO] = Demo site logs"
echo "🔌 Starting Insertr server with all sites..."
echo ""
# Function to cleanup background processes
cleanup() {
echo ""
echo "🛑 Shutting down servers..."
kill $SERVER_PID $DEMO_PID 2>/dev/null || true
wait $SERVER_PID $DEMO_PID 2>/dev/null || true
echo "🛑 Shutting down server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
echo "✅ Shutdown complete"
exit 0
}
trap cleanup SIGINT SIGTERM
# Start API server with prefixed output
echo "🔌 Starting API server (localhost:8080)..."
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [SERVER] /' &
SERVER_PID=$!
# Wait for server startup
echo "⏳ Waiting for API server startup..."
sleep 3
# Check server health
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
echo "✅ API server ready!"
else
echo "⚠️ API server may not be ready yet"
fi
echo ""
echo "🌐 Starting demo site (localhost:3000)..."
echo "📝 Full-stack ready - edit content with real-time persistence!"
echo ""
# Start enhanced demo site with prefixed output (this will block) - use local installation
cd {{justfile_directory()}} && npx --prefer-offline live-server test-sites/demo-site_enhanced --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
DEMO_PID=$!
# Wait for both processes
wait $DEMO_PID $SERVER_PID
# Demo site only (for specific use cases)
# Start development server for about page
dev-about: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting full-stack development (about page)..."
# Start server (serves API + all static sites)
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode &
SERVER_PID=$!
sleep 3
npx --prefer-offline live-server test-sites/demo-site --port=3000 --host=localhost --open=/about.html
kill $SERVER_PID 2>/dev/null || true
echo ""
echo "🌐 All sites available at:"
echo " Demo site: http://localhost:8080/sites/demo/"
echo " Simple site: http://localhost:8080/sites/simple/"
echo " Dan Eden site: http://localhost:8080/sites/dan-eden/"
echo ""
echo "📝 Full-stack ready - edit content with real-time persistence!"
echo "🔄 Press Ctrl+C to shutdown"
echo ""
# Wait for server process
wait $SERVER_PID
# Start development server for about page
dev-about: build-lib build
#!/usr/bin/env bash
echo "🚀 Starting full-stack development..."
echo "🌐 About page available at: http://localhost:8080/sites/demo/about.html"
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode
# Check project status and validate setup
check:
npm run check
# Start demo for a specific test site
demo site="":
#!/usr/bin/env bash
if [ "{{site}}" = "" ]; then
echo "📋 Available Insertr Demo Sites:"
echo "=================================="
echo ""
echo "🏠 Built-in Demo:"
echo " default - Default insertr demo site"
echo ""
echo "🌐 Test Site Demos:"
echo " dan-eden - Dan Eden's portfolio"
echo " simple - Simple test site"
echo ""
echo "📝 Usage:"
echo " just demo default - Start default demo"
echo " just demo dan-eden - Start Dan Eden portfolio demo"
echo " just demo simple - Start simple test site demo"
echo ""
echo "💡 Note: Sites are auto-enhanced on first run"
elif [ "{{site}}" = "default" ] || [ "{{site}}" = "demo" ]; then
if [ ! -d "./test-sites/demo-site_enhanced" ]; then
echo "🔧 Default demo not ready - enhancing now..."
just build
./insertr enhance test-sites/demo-site --output test-sites/demo-site_enhanced --config test-sites/demo-site/insertr.yaml
fi
echo "🚀 Starting default demo site..."
just demo-site "demo" "./test-sites/demo-site_enhanced" "3000"
elif [ "{{site}}" = "dan-eden" ]; then
if [ ! -d "./test-sites/simple/dan-eden-portfolio_enhanced" ]; then
echo "🔧 Dan Eden demo not ready - enhancing now..."
just build
./insertr enhance test-sites/simple/dan-eden-portfolio --output test-sites/simple/dan-eden-portfolio_enhanced --config test-sites/simple/dan-eden-portfolio/insertr.yaml
fi
echo "🚀 Starting Dan Eden portfolio demo..."
just demo-site "dan-eden" "./test-sites/simple/dan-eden-portfolio_enhanced" "3000"
elif [ "{{site}}" = "simple" ]; then
if [ ! -d "./test-sites/simple/test-simple_enhanced" ]; then
echo "🔧 Simple demo not ready - enhancing now..."
just build
./insertr enhance test-sites/simple/test-simple --output test-sites/simple/test-simple_enhanced --config test-sites/simple/test-simple/insertr.yaml
fi
echo "🚀 Starting simple test site demo..."
just demo-site "simple" "./test-sites/simple/test-simple_enhanced" "3000"
else
echo "❌ Unknown demo site: {{site}}"
echo ""
echo "📋 Available demo sites:"
echo " default - Default demo site"
echo " dan-eden - Dan Eden portfolio"
echo " simple - Simple test site"
echo ""
echo "🔧 Other commands:"
echo " just demo - Show all demo sites"
exit 1
fi
# Generic demo site launcher (internal command)
demo-site site_id path port="3000": build
#!/usr/bin/env bash
echo "🚀 Starting {{site_id}} demo..."
echo "📁 Path: {{path}}"
echo "🌐 Port: {{port}}"
echo "================================================"
echo ""
# Function to cleanup background processes
cleanup() {
echo ""
echo "🛑 Shutting down servers..."
kill $SERVER_PID $DEMO_PID 2>/dev/null || true
wait $SERVER_PID $DEMO_PID 2>/dev/null || true
echo "✅ Shutdown complete"
exit 0
}
trap cleanup SIGINT SIGTERM
# Start API server
echo "🔌 Starting API server (localhost:8080)..."
INSERTR_DATABASE_PATH=./insertr.db ./insertr serve --dev-mode 2>&1 | sed 's/^/🔌 [{{site_id}}] /' &
SERVER_PID=$!
# Wait for server startup
echo "⏳ Waiting for API server startup..."
sleep 3
# Check server health
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
echo "✅ API server ready!"
else
echo "⚠️ API server may not be ready yet"
fi
echo ""
echo "🌐 Starting {{site_id}} (localhost:{{port}})..."
echo "📝 Demo ready - test insertr functionality!"
echo ""
# Start demo site
npx --prefer-offline live-server "{{path}}" --port={{port}} --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [{{site_id}}] /' &
DEMO_PID=$!
# Wait for both processes
wait $DEMO_PID $SERVER_PID
# Simple demo launcher - all sites now served from main server
demo:
@echo "🌐 All demo sites are served from the main server:"
@echo " http://localhost:8080/sites/demo/ - Main demo site"
@echo " http://localhost:8080/sites/simple/ - Simple test site"
@echo " http://localhost:8080/sites/dan-eden/ - Dan Eden portfolio"
@echo ""
@echo "🚀 To start the development server:"
@echo " just dev"
# Build the entire project (library + unified binary)
build:
@@ -281,8 +167,7 @@ status:
@echo ""
@echo "🚀 Development Commands:"
@echo " just dev - Full-stack development (recommended)"
@echo " just demo [site] - Start specific demo site (or show available demos)"
@echo " just demo - Show available demo sites"
@echo " just serve - API server only (localhost:8080)"
@echo " just enhance - Build-time content injection"
@echo ""