Skip to content

feat: track request IP addresses in modal preview server#141

Open
GindaChen wants to merge 1 commit intomainfrom
feat/track-request-ip
Open

feat: track request IP addresses in modal preview server#141
GindaChen wants to merge 1 commit intomainfrom
feat/track-request-ip

Conversation

@GindaChen
Copy link
Collaborator

Summary

Add IP address logging for every incoming request to the Modal preview server.

Changes

A lightweight Starlette reverse-proxy is inserted between Modal's exposed port (10000) and the FastAPI backend (moved to internal port 10001). The proxy:

  • Extracts the real client IP from X-Forwarded-For / X-Real-IP headers (set by Modal's proxy layer), falling back to request.client.host
  • Logs every request and response: REQUEST 1.2.3.4 GET /sessions / RESPONSE 1.2.3.4 GET /sessions -> 200
  • Supports SSE/streaming responses (e.g. /chat endpoint) via httpx streaming API

Architecture

Modal exposed port 10000 → IP-tracking Starlette proxy → FastAPI backend on port 10001

Only modal_preview.py is modified. No changes to server/server.py or other files.

Testing

  • Syntax check: py_compile passes
  • No new dependencies required (httpx, uvicorn, starlette are already in the image)

Add a lightweight Starlette reverse-proxy in front of the FastAPI
backend that logs every request's client IP address.

- Backend moved to internal port 10001
- IP-tracking proxy runs on exposed port 10000
- Extracts real IP from X-Forwarded-For / X-Real-IP headers
- Supports SSE/streaming responses (e.g. /chat endpoint)
- Logs lines like: REQUEST 1.2.3.4 GET /sessions
@GindaChen GindaChen added the help wanted: dev Extra attention is needed label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted: dev Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant