Step 6: Images Service Integration
- Integrated image-service from site00 as second microservice - Maintained proxy and caching functionality - Added Images service to docker-compose - Configured Console API Gateway routing to Images - Updated environment variables in .env - Successfully tested image proxy endpoints Services now running: - Console (API Gateway) - Users Service - Images Service (proxy & cache) - MongoDB & Redis Next: Kafka event system implementation 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -21,6 +21,7 @@ app = FastAPI(
|
||||
|
||||
# Service URLs from environment
|
||||
USERS_SERVICE_URL = os.getenv("USERS_SERVICE_URL", "http://users-backend:8000")
|
||||
IMAGES_SERVICE_URL = os.getenv("IMAGES_SERVICE_URL", "http://images-backend:8000")
|
||||
|
||||
# CORS middleware
|
||||
app.add_middleware(
|
||||
@ -111,9 +112,16 @@ async def system_status():
|
||||
except:
|
||||
services_status["users"] = "offline"
|
||||
|
||||
# Check Images service
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(f"{IMAGES_SERVICE_URL}/health", timeout=2.0)
|
||||
services_status["images"] = "online" if response.status_code == 200 else "error"
|
||||
except:
|
||||
services_status["images"] = "offline"
|
||||
|
||||
# Other services (not yet implemented)
|
||||
services_status["oauth"] = "pending"
|
||||
services_status["images"] = "pending"
|
||||
services_status["applications"] = "pending"
|
||||
services_status["data"] = "pending"
|
||||
services_status["statistics"] = "pending"
|
||||
@ -133,6 +141,43 @@ async def protected_route(current_user = Depends(get_current_user)):
|
||||
"user": current_user.username
|
||||
}
|
||||
|
||||
# API Gateway - Route to Images service
|
||||
@app.api_route("/api/images/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||
async def proxy_to_images(path: str, request: Request):
|
||||
"""Proxy requests to Images service (public for image proxy)"""
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
# Build the target URL
|
||||
url = f"{IMAGES_SERVICE_URL}/api/v1/{path}"
|
||||
|
||||
# Get request body if exists
|
||||
body = None
|
||||
if request.method in ["POST", "PUT", "PATCH"]:
|
||||
body = await request.body()
|
||||
|
||||
# Forward the request
|
||||
response = await client.request(
|
||||
method=request.method,
|
||||
url=url,
|
||||
headers={
|
||||
key: value for key, value in request.headers.items()
|
||||
if key.lower() not in ["host", "content-length"]
|
||||
},
|
||||
content=body,
|
||||
params=request.query_params
|
||||
)
|
||||
|
||||
# Return the response
|
||||
return Response(
|
||||
content=response.content,
|
||||
status_code=response.status_code,
|
||||
headers=dict(response.headers)
|
||||
)
|
||||
except httpx.ConnectError:
|
||||
raise HTTPException(status_code=503, detail="Images service unavailable")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
# API Gateway - Route to Users service
|
||||
@app.api_route("/api/users/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||
async def proxy_to_users(path: str, request: Request, current_user = Depends(get_current_user)):
|
||||
|
||||
Reference in New Issue
Block a user