#!/bin/bash

# Simple update server for testing auto-update feature

PORT=9000
UPDATE_DIR="./dist"

echo "🚀 Starting StreamFlow Update Server"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📁 Serving from: $UPDATE_DIR"
echo "🌐 Server URL: http://localhost:$PORT"
echo ""
echo "The app will check this server for updates."
echo "Press Ctrl+C to stop the server."
echo ""

cd "$(dirname "$0")"

# Create a simple HTTP server using Python
python3 -m http.server $PORT --directory "$UPDATE_DIR" 2>/dev/null || \
python -m SimpleHTTPServer $PORT 2>/dev/null || \
node -e "require('http').createServer((req, res) => { \
  const fs = require('fs'); \
  const path = require('path'); \
  const filePath = path.join('$UPDATE_DIR', req.url === '/' ? 'index.html' : req.url); \
  fs.readFile(filePath, (err, data) => { \
    if (err) { res.writeHead(404); res.end('Not found'); return; } \
    res.writeHead(200); res.end(data); \
  }); \
}).listen($PORT, () => console.log('Server running on port $PORT'));"
