Spaces:
Sleeping
title: Simple Request Logger
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
Simple Request Logging Server (Hugging Face Compatible)
This repository contains a simple Flask application designed to run in a Docker container. It listens for incoming POST requests on the root path (/) and logs the request headers and body (JSON or raw) to the standard output. This is useful for debugging or inspecting webhook payloads.
The application is configured to run on port 7860, which is commonly used for Hugging Face Spaces deployments.
Files
app.py: The main Flask application code.requirements.txt: Lists the Python dependencies (Flask).Dockerfile: Instructions for building the Docker image.README.md: This file.
Prerequisites
- Docker installed on your system.
Build the Docker Image
Navigate to the directory containing the Dockerfile and run the following command:
docker build -t request-logger .
Run the Docker Container
To run the container and map the internal port 7860 to a port on your host machine (e.g., 7860), use:
docker run -p 7860:7860 request-logger
The server will start, and you should see output indicating it's listening on 0.0.0.0:7860.
Sending Requests
You can send POST requests to the server using tools like curl or any HTTP client.
Example using curl (JSON payload):
curl -X POST http://localhost:7860/ \
-H "Content-Type: application/json" \
-H "X-Custom-Header: MyValue" \
-d '{"key": "value", "message": "Hello Server!"}'
Example using curl (Form data):
curl -X POST http://localhost:7860/ \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "param1=value1¶m2=value2"
Example using curl (Plain text):
curl -X POST http://localhost:7860/ \
-H "Content-Type: text/plain" \
-d "This is a plain text body."
Viewing Logs
The request details (headers and body) will be printed to the terminal where you ran the docker run command.
Deployment on Hugging Face Spaces
- Create a new Space on Hugging Face (https://huggingface.co/new-space).
- Choose "Docker" as the Space SDK. The settings in this
README.mdfile (likesdk: dockerandapp_port: 7860) will configure the Space automatically. - Upload or push (
git) theapp.py,requirements.txt,Dockerfile, and this updatedREADME.mdto your Space repository. - Hugging Face will automatically build the Docker image and deploy the application using the information from the
Dockerfileand the YAML header in this README. The application will be accessible athttps://<your-username>-<your-space-name>.hf.space/. Remember that requests should be sent to the root path (/).