|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Test script for reverse proxy path rewriting experiment |
| 4 | +echo "🧪 Testing Reverse Proxy Path Rewriting Experiment" |
| 5 | +echo "==================================================" |
| 6 | +echo |
| 7 | + |
| 8 | +# Colors for output |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +NC='\033[0m' # No Color |
| 13 | + |
| 14 | +# Check if app is running |
| 15 | +echo "1. Checking if CodiMD is running on port 3000..." |
| 16 | +if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/ | grep -q "200\|302\|301"; then |
| 17 | + echo -e " ${GREEN}✅ CodiMD is running on port 3000${NC}" |
| 18 | +else |
| 19 | + echo -e " ${RED}❌ CodiMD is NOT running on port 3000${NC}" |
| 20 | + echo -e " ${YELLOW}Start it with: npm start${NC}" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | +echo |
| 24 | + |
| 25 | +# Check if Caddy is running |
| 26 | +echo "2. Checking if Caddy is running on port 8080..." |
| 27 | +if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ 2>/dev/null | grep -q "301\|200"; then |
| 28 | + echo -e " ${GREEN}✅ Caddy is running on port 8080${NC}" |
| 29 | +else |
| 30 | + echo -e " ${RED}❌ Caddy is NOT running on port 8080${NC}" |
| 31 | + echo -e " ${YELLOW}Start it with: caddy run --config Caddyfile.experiment${NC}" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | +echo |
| 35 | + |
| 36 | +# Test root redirect |
| 37 | +echo "3. Testing root redirect (/ → /codimd/)..." |
| 38 | +response=$(curl -s -I http://localhost:8080/ 2>/dev/null) |
| 39 | +if echo "$response" | grep -q "301 Moved Permanently" && echo "$response" | grep -q "Location:.*codimd"; then |
| 40 | + echo -e " ${GREEN}✅ Root redirect working${NC}" |
| 41 | +else |
| 42 | + echo -e " ${RED}❌ Root redirect failed${NC}" |
| 43 | + echo "$response" |
| 44 | +fi |
| 45 | +echo |
| 46 | + |
| 47 | +# Test /codimd redirect to /codimd/ |
| 48 | +echo "4. Testing /codimd redirect (→ /codimd/)..." |
| 49 | +response=$(curl -s -I http://localhost:8080/codimd 2>/dev/null) |
| 50 | +if echo "$response" | grep -q "301" && echo "$response" | grep -q "Location:.*codimd/"; then |
| 51 | + echo -e " ${GREEN}✅ /codimd redirect working${NC}" |
| 52 | +else |
| 53 | + echo -e " ${RED}❌ /codimd redirect failed${NC}" |
| 54 | + echo "$response" |
| 55 | +fi |
| 56 | +echo |
| 57 | + |
| 58 | +# Test main app access |
| 59 | +echo "5. Testing main app access (/codimd/)..." |
| 60 | +response=$(curl -s -I http://localhost:8080/codimd/ 2>/dev/null) |
| 61 | +if echo "$response" | grep -q "200 OK"; then |
| 62 | + echo -e " ${GREEN}✅ Main app accessible${NC}" |
| 63 | +else |
| 64 | + echo -e " ${RED}❌ Main app access failed${NC}" |
| 65 | + echo "$response" |
| 66 | +fi |
| 67 | +echo |
| 68 | + |
| 69 | +# Test static assets |
| 70 | +echo "6. Testing static assets (/codimd/favicon.png)..." |
| 71 | +response=$(curl -s -I http://localhost:8080/codimd/favicon.png 2>/dev/null) |
| 72 | +if echo "$response" | grep -q "200 OK"; then |
| 73 | + echo -e " ${GREEN}✅ Static assets working${NC}" |
| 74 | +else |
| 75 | + echo -e " ${RED}❌ Static assets failed${NC}" |
| 76 | + echo "$response" |
| 77 | +fi |
| 78 | +echo |
| 79 | + |
| 80 | +# Test build assets |
| 81 | +echo "7. Testing webpack bundles (/codimd/build/...)..." |
| 82 | +# Find a build file |
| 83 | +buildFile=$(ls public/build/*.eot 2>/dev/null | head -1 | xargs basename 2>/dev/null) |
| 84 | +if [ -n "$buildFile" ]; then |
| 85 | + response=$(curl -s -I "http://localhost:8080/codimd/build/$buildFile" 2>/dev/null) |
| 86 | + if echo "$response" | grep -q "200 OK"; then |
| 87 | + echo -e " ${GREEN}✅ Build assets working${NC}" |
| 88 | + else |
| 89 | + echo -e " ${RED}❌ Build assets failed${NC}" |
| 90 | + echo "$response" |
| 91 | + fi |
| 92 | +else |
| 93 | + echo -e " ${YELLOW}⚠️ No build files found to test${NC}" |
| 94 | +fi |
| 95 | +echo |
| 96 | + |
| 97 | +# Test what the app receives (check headers) |
| 98 | +echo "8. Checking what app receives from Caddy..." |
| 99 | +echo " Testing if X-Forwarded-Prefix header is passed..." |
| 100 | +# This would need app logging to verify |
| 101 | +echo -e " ${YELLOW}ℹ️ Check app logs to verify X-Forwarded-Prefix: /codimd${NC}" |
| 102 | +echo |
| 103 | + |
| 104 | +# Test direct app access (should work at root) |
| 105 | +echo "9. Testing direct app access (without proxy)..." |
| 106 | +response=$(curl -s -I http://localhost:3000/ 2>/dev/null) |
| 107 | +if echo "$response" | grep -q "200\|302\|301"; then |
| 108 | + echo -e " ${GREEN}✅ App works at root (no URL path mounting)${NC}" |
| 109 | + echo -e " ${YELLOW}ℹ️ This means path rewriting experiment is active${NC}" |
| 110 | +else |
| 111 | + echo -e " ${YELLOW}⚠️ App response: $(echo "$response" | head -1)${NC}" |
| 112 | +fi |
| 113 | +echo |
| 114 | + |
| 115 | +echo "==================================================" |
| 116 | +echo "🎯 Experiment Status Summary" |
| 117 | +echo "==================================================" |
| 118 | +echo |
| 119 | +echo "The reverse proxy path rewriting approach requires:" |
| 120 | +echo "1. ✅ Caddy to strip /codimd prefix before forwarding" |
| 121 | +echo "2. ✅ App to run at root (no URL path mounting)" |
| 122 | +echo "3. ⚠️ App to generate URLs with /codimd (via serverURL config)" |
| 123 | +echo "4. ⚠️ Socket.IO path rewriting in Caddy" |
| 124 | +echo |
| 125 | +echo "Access the app at: http://localhost:8080/codimd/" |
| 126 | +echo |
0 commit comments