-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.sh
More file actions
executable file
·65 lines (51 loc) · 1.74 KB
/
example.sh
File metadata and controls
executable file
·65 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Example script demonstrating the caching proxy server
# This script shows how to build, run, and test the caching proxy
echo "🚀 Building the caching proxy server..."
make build
if [ $? -ne 0 ]; then
echo "❌ Build failed. Please check the error messages above."
exit 1
fi
echo "✅ Build successful!"
echo ""
echo "🔧 Starting the caching proxy server on port 3000..."
echo " Forwarding requests to: http://dummyjson.com"
echo ""
# Start the server in the background
./caching-proxy --port 3000 --origin http://dummyjson.com &
SERVER_PID=$!
# Wait a moment for the server to start
sleep 2
echo "🧪 Testing the proxy server..."
echo ""
# Test 1: First request (should be a cache MISS)
echo "📡 Test 1: First request to /products (Cache MISS expected)"
curl -s -I http://localhost:3000/products | grep "X-Cache"
echo ""
# Test 2: Second request (should be a cache HIT)
echo "📡 Test 2: Second request to /products (Cache HIT expected)"
curl -s -I http://localhost:3000/products | grep "X-Cache"
echo ""
# Test 3: Different endpoint
echo "📡 Test 3: Request to /users (Cache MISS expected)"
curl -s -I http://localhost:3000/users | grep "X-Cache"
echo ""
# Test 4: Same endpoint again (should be a cache HIT)
echo "📡 Test 4: Second request to /users (Cache HIT expected)"
curl -s -I http://localhost:3000/users | grep "X-Cache"
echo ""
echo "🧹 Cleaning up..."
# Stop the server
kill $SERVER_PID 2>/dev/null
echo ""
echo "✨ Example completed successfully!"
echo ""
echo "💡 To run the server manually:"
echo " ./caching-proxy --port 3000 --origin http://dummyjson.com"
echo ""
echo "💡 To clear the cache:"
echo " ./caching-proxy clear-cache"
echo ""
echo "💡 To see all available commands:"
echo " make help"