Request Mirror is a real-time request debugging application inspired by RequestBin. The main difference between RequestBin and Request Mirror is that the latter updates in real-time, using WebSockets. So whenever you make a request to a mirror, you see it appear on the webpage immediately, without needing to refresh the page.
Request Mirror is an experiment, so little effort has been made to optimize performance. It also has zero tests.
Install Docker if you haven't yet.
Run Redis + Request Mirror
$ docker-compose up
Build the Docker Image yourself
This is optional, because the Docker Compose file uses the existing docker image from Docker Hub.
$ docker build -t request-mirror:latest
If you want to use your locally built image, replace daan/request-mirror:latest
in docker-compose.yml
with
request-mirror:latest
Request Mirror requires Redis to store active "mirrors". It expects Redis running on the default host and port:
localhost:6379
. The provided Docker Compose file includes redis. During development, you can run it separately
without running Request Mirror in Docker: docker-compose up -d redis
Request Mirror also requires Yarn to be installed. Installation instructions can be found here.
You can now install the frontend dependencies of Request Mirror:
$ yarn
Now you should install the required Python packages:
$ pip install -r requirements.txt
It is recommended to do this inside a Virtual Environment
After you've taken care of all the dependencies, you can run Request Mirror:
$ yarn run dev
This will run the Flask app and the in development mode, and also run a watcher that watches the frontend files and re-packages the frontend whenever one of the source files changes. The frontend is served by Flask by the way.
You can also pre-build the frontend, and run only the Flask app:
$ yarn run build
$ python app.py
Request Mirror has a very simple architecture
The backend consists of a Flask app that serves the home page and the mirror pages and receives requests for mirrors. Users can create a mirror with a name of their own choosing, or have Request Mirror generate a random string. The mirror name or "code" is stored in Redis with an expiry time of 15 minutes. The expirty time - or time-to-live - is updated whenever a new request is sent to that mirror, or when that mirror's page is visited.
The backend uses Flask-SocketIO to take care of real-time communication with the frontend.
There are basically 2 views in Request Mirror: the home page and the mirror pages. Each of these views is served separately from the backend, so the application as a whole is not a Single Page App. The mirror view/page however, is a React app that is built and bundled using Yarn and Parcel.
Request Mirror can be configured using the following environment variables:
Environment variable | description | default |
---|---|---|
REDIS_URL |
Heroku-style URL to connect to Redis db | redis://localhost:6379 |
REDIS_MAX_CONNECTIONS |
Max. number of simultaneous connections Request Mirror can make to Redis | None |
EXPIRATION_TIME |
How long inactive mirrors should exist (in seconds) | 60 * 60 * 24 seconds (24 hours) |
MAX_REQUESTS |
Max. number of requests Request Mirror should save per mirror before. Works like a FIFO queue | 20 |