This is a scalable QR Code Generator API that allows users to generate QR codes, store them in a specified MinIO bucket, and view logs related to the QR code generation process.
- Generate QR codes with customizable content, format, and size.
- Store generated QR codes in a MinIO bucket.
- View logs for QR code generation, including file name, creation time, and file size.
- Scalable to multiple containers with unique log file naming to avoid conflicts.
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory and specify the following:LOG_USERNAME=admin
LOG_PASSWORD=supersecret
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=your-region
MINIO_ENDPOINT=your-minio-endpoint
MINIO_ACCESS_KEY=your-minio-access-key
MINIO_SECRET_KEY=your-minio-secret-key -
Build and run the application:
npm start
Endpoint: /qr-code/generate
Method: POST
Description: Generates a QR code and stores it in the MinIO bucket. The content, format, and size of the QR code are configurable via the request body.
Request Body Example:
{
"text": "https://example.com",
"format": "png",
"pixel": 300
}
Endpoint: /logs
Method: GET
Description: Displays a list of log files that show QR code generation logs, including file name, creation time, and file size.
Note: The logs endpoint is protected by basic authentication. Use the credentials provided in the .env
file to access it.
To access the logs, visit /logs
in your browser. The logs are displayed in a table with clickable links for each log file, showing the creation time and file size in a human-readable format.
The application is designed to run in a multi-container environment. Each container writes its logs to a unique file using a combination of a UUID and timestamp to avoid conflicts. All containers write to a shared directory or storage solution (such as NFS or EFS in Kubernetes).
- Logs are protected by basic authentication using credentials from the
.env
file. - Environment variables are used for sensitive information such as MinIO and AWS credentials.
- Express: Web framework for handling API requests.
- Winston: Logging library with support for daily file rotation.
- Winston-Daily-Rotate-File: Rotates log files daily and handles multiple log files efficiently.
- Sharp: Used for processing images (QR codes) and adding a logo to the QR code.
- MinIO: Object storage solution where QR codes are stored.
docker-compose build
docker-compose up -d
docker-compose ps -q | grep . && docker-compose down && docker-compose up --build
This project is licensed under the MIT License.