experiments in a post-browser web
at main 110 lines 3.3 kB view raw
1#!/bin/bash 2# Start dev server with seeded test data for iOS simulator testing 3# 4# Usage: ./scripts/dev-server-with-data.sh 5# 6# This script: 7# 1. Starts the backend server on localhost:3000 8# 2. Seeds test data via the API 9# 3. Shows connection info for iOS simulator 10# 11# To stop: Ctrl+C or kill the process 12 13set -e 14 15SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 16PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 17SERVER_DIR="$PROJECT_DIR/backend/server" 18 19# Configuration 20PORT="${PORT:-3000}" 21API_KEY="${API_KEY:-dev-test-key-$(date +%s)}" 22 23# Get local IP for iOS simulator to connect 24LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || echo "localhost") 25 26echo "==========================================" 27echo " Peek Dev Server with Test Data" 28echo "==========================================" 29echo "" 30echo "Server URL: http://$LOCAL_IP:$PORT" 31echo "API Key: $API_KEY" 32echo "" 33 34# Export for server 35export PORT 36export API_KEY 37 38# Start server in background, capture PID 39cd "$SERVER_DIR" 40node index.js & 41SERVER_PID=$! 42 43# Wait for server to be ready 44echo "Starting server..." 45for i in {1..30}; do 46 if curl -s "http://localhost:$PORT/" > /dev/null 2>&1; then 47 echo "Server is ready!" 48 break 49 fi 50 sleep 0.5 51done 52 53# Seed test data 54echo "" 55echo "Seeding test data..." 56 57# Create test items with profile parameter (simulating mobile client) 58PROFILE_PARAM="profile=dev-test-profile&slug=default" 59 60curl -s -X POST "http://localhost:$PORT/items?$PROFILE_PARAM" \ 61 -H "Authorization: Bearer $API_KEY" \ 62 -H "Content-Type: application/json" \ 63 -d '{"type": "url", "content": "https://example.com/test-1", "tags": ["test", "example"]}' > /dev/null 64 65curl -s -X POST "http://localhost:$PORT/items?$PROFILE_PARAM" \ 66 -H "Authorization: Bearer $API_KEY" \ 67 -H "Content-Type: application/json" \ 68 -d '{"type": "url", "content": "https://github.com/test-repo", "tags": ["github", "code"]}' > /dev/null 69 70curl -s -X POST "http://localhost:$PORT/items?$PROFILE_PARAM" \ 71 -H "Authorization: Bearer $API_KEY" \ 72 -H "Content-Type: application/json" \ 73 -d '{"type": "text", "content": "Test note from server", "tags": ["note", "test"]}' > /dev/null 74 75curl -s -X POST "http://localhost:$PORT/items?$PROFILE_PARAM" \ 76 -H "Authorization: Bearer $API_KEY" \ 77 -H "Content-Type: application/json" \ 78 -d '{"type": "url", "content": "https://news.ycombinator.com", "tags": ["news", "tech"]}' > /dev/null 79 80echo "Created 4 test items" 81 82# Show current items 83echo "" 84echo "Current items on server:" 85curl -s "http://localhost:$PORT/items?$PROFILE_PARAM" \ 86 -H "Authorization: Bearer $API_KEY" | python3 -c " 87import sys, json 88data = json.load(sys.stdin) 89for item in data.get('items', []): 90 content = item.get('content', '')[:50] 91 tags = ', '.join(item.get('tags', [])) 92 print(f\" [{item['type']}] {content} (tags: {tags})\")" 93 94echo "" 95echo "==========================================" 96echo " iOS Simulator Setup" 97echo "==========================================" 98echo "" 99echo "In the iOS app Settings, configure:" 100echo " Server URL: http://$LOCAL_IP:$PORT" 101echo " API Key: $API_KEY" 102echo "" 103echo "Then tap 'Pull' or 'Sync' to fetch the test data." 104echo "" 105echo "Press Ctrl+C to stop the server." 106echo "==========================================" 107echo "" 108 109# Wait for server process 110wait $SERVER_PID