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.
The request body must be a JSON object containing the following fields:
postId: The unique identifier of the post to which the comment is being added.
commentParentId: The identifier of the parent comment (if any) to support threaded comments. This can be
null for top-level comments.
name: The name of the person submitting the comment.
email: The email address of the person submitting the comment. (Note: This will not be published but may be used for validation or notifications.)
commentText: The text of the comment.
Parse Request: Extract
commentText from the incoming request.
Comment File Update:
src/content/comments/[postId].json exists; create it if not.
Commit and Push:
comments branch of the repository.
Cleanup: Ensure temporary files and the cloned repository are cleaned up after the operation.
The function should gracefully handle and log errors, including:
Comprehensive testing should cover:
Deploy the serverless function on Vercel, ensuring that all environment variables and permissions are correctly set up.