Comment section for static pages
- Java 82.1%
- JavaScript 14.1%
- Dockerfile 2.2%
- Shell 1.6%
| app | deployment fixes | |
| db/migrations | gradle init | |
| gradle | gradle init | |
| .dockerignore | deployment fixes | |
| .gitattributes | gradle init | |
| .gitignore | gradle init | |
| docker-compose.yaml | deployment fixes | |
| Dockerfile | deployment fixes | |
| gradle.properties | gradle init | |
| gradlew | gradle init | |
| gradlew.bat | gradle init | |
| init_test_db.sh | testing setup | |
| LICENSE | Initial commit | |
| README.md | todo/status comment | |
| settings.gradle | gradle init | |
comments-api
Simple REST API that enables storing comments for any static site.
Notes/TODOs: this repo is to test Java dev workflow on a sample app. For this project to be usable in prod:
- user auth needs to be added
- replies not supported
Endpoints
| Endpoint | Method | Body params | Description |
|---|---|---|---|
| /api/comments/{host}/{path} | GET | - | List comments at given host and path |
| /api/comments | POST | host, path, author, content | Add new comment |
| /api/comments/{id} | DELETE | - | Delete comment |
| /api/votes | POST | commentId, score | Vote on given comment |
Setup
- Run the service
It requires existing postgres database.
podman run -d \
-e COMMENTS_HOST=0.0.0.0 \
-e COMMENTS_PORT=7654 \
-e COMMENTS_DB_URI=postgresql://host.containers.internal:5432 \
-e COMMENTS_DB_NAME=comments_dev \
-e COMMENTS_DB_USER=postgres \
-e COMMENTS_DB_PASSWORD=postgres \
-p 7654:7654 \
docker.io/pieca/comments-api:0.2
Or run docker compose for both comments-api and postgres:
podman-compose up -d
- Add the following to html (adjust
<template>style as needed):
<!-- inside head -->
<script src="<COMMENTS_API_ENDPOINT>/comments-api.js"></script>
<script>window.loadComments("<COMMENTS_API_ENDPOINT>")</script>
<!-- where the comments should appear -->
<div id="comments-api-comments"></div>
<!-- this can be anywhere in the body -->
<template id="comments-api-new-comment">
<p><input type="text" id="comments-api-new-comment-author" required minlength="1" size="10" placeholder="Your name..." /></p>
<p><textarea name="" id="comments-api-new-comment-text" cols="30" rows="5" placeholder="Your comment..."></textarea></p>
<p><button id="comments-api-new-comment-button" onclick="window.saveComment(this)">Comment</button></p>
</template>
<template id="comments-api-comment">
<p class="comments-api-comment-author"></p>
<p class="comments-api-comment-ts"></p>
<p class="comments-api-comment-content"></p>
<p class="comments-api-comment-score"></p>
<p><button class="comments-api-comment-vote" data-comment-id="" onclick="window.vote(this, -1)">Downvote</button></p>
<p><button class="comments-api-comment-vote" data-comment-id="" onclick="window.vote(this, 1)">Upvote</button></p>
</template>
build
sudo podman build . -t docker.io/pieca/comments-api:0.2