Serverless API for Comment Submission

Overview

This document specifies the serverless function deployed on Vercel for handling comment submissions to blog posts. The function will receive POST requests containing comment data, update the relevant post’s comment file in the repository on a separate comments branch, and commit the changes.

Endpoint

Request Body

The request body must be a JSON object containing the following fields:

Functionality

  1. Parse Request: Extract postId, commentParentId, name, email, and commentText from the incoming request.

  2. Repository Setup:

  3. Comment File Update:

  4. Commit and Push:

  5. Cleanup: Ensure temporary files and the cloned repository are cleaned up after the operation.

Security and Best Practices

Dependencies

Error Handling

The function should gracefully handle and log errors, including:

Testing

Comprehensive testing should cover:

Deployment

Deploy the serverless function on Vercel, ensuring that all environment variables and permissions are correctly set up.