- Initial setup of the back-end microservice project.
Fragments is a microservice built with Node.js that allows users to create, update, delete, and retrieve data fragments (small pieces of content). The service supports different content types such as plain text, markdown, JSON, and various image formats. It also supports converting between certain formats (e.g., markdown to HTML, image resizing).
This service is designed to be highly scalable and can be deployed using Docker. It uses AWS DynamoDB for storing metadata about the fragments and AWS S3 for storing the fragment data itself. The service also uses the sharp
library for image processing and format conversion.
Before you start, make sure you have the following installed on your machine:
- Node.js (>= 18.17.0)
- Docker and Docker Compose
- AWS CLI configured with access to DynamoDB and S3 (for local development with LocalStack)
This service uses AWS Cognito for authentication. Ensure you have valid AWS Cognito credentials and set them in the environment variables.
POST /v1/fragments
Create a new fragment by sending raw data in the request body. The Content-Type header determines the type of fragment.
GET /v1/fragments
GET /v1/fragments/:id
Retrieve all fragments for the authenticated user or a specific fragment by ID. Supports retrieving metadata or the actual data.
PUT /v1/fragments/:id
Update an existing fragment by sending new data in the request body. The Content-Type must match the fragment's existing type.
DELETE /v1/fragments/:id
Delete a specific fragment by ID.
Certain content types support conversion, such as:
- Markdown to HTML
- Image format conversion (e.g., PNG to JPEG)
Use extensions in the URL to request the converted format:
GET /v1/fragments/:id.html
GET /v1/fragments/:id.png
Ensure Docker and Docker Compose are installed. Start the services:
docker compose up --build -d
This project uses Jest for testing. To run tests, use the following command:
npm test
Ensure that the LOG_LEVEL is set to debug in env.jest for more detailed test logs.
Deployment can be handled by deploying the Docker image to a cloud platform like AWS ECS, GCP, or Azure. Ensure that the necessary AWS credentials are available in the environment where the service is deployed.
- Cannot do operations on a non-existent table: Ensure the DynamoDB table is created before the service tries to access it. Use the provided script or AWS CLI to create and verify the table.
- Sharp module errors: Ensure Node.js version is compatible with sharp and the correct dependencies are installed. For Docker, the Node.js version should be >= 18.17.0.