1
0
Fork
You've already forked comments-api
0
Comment section for static pages
  • Java 82.1%
  • JavaScript 14.1%
  • Dockerfile 2.2%
  • Shell 1.6%
Find a file
2026年05月06日 21:59:53 +02:00
app deployment fixes 2025年11月12日 20:19:10 +01:00
db/migrations gradle init 2025年11月04日 23:11:20 +01:00
gradle gradle init 2025年11月04日 23:11:20 +01:00
.dockerignore deployment fixes 2025年11月12日 20:19:10 +01:00
.gitattributes gradle init 2025年11月04日 23:11:20 +01:00
.gitignore gradle init 2025年11月04日 23:11:20 +01:00
docker-compose.yaml deployment fixes 2025年11月12日 20:19:10 +01:00
Dockerfile deployment fixes 2025年11月12日 20:19:10 +01:00
gradle.properties gradle init 2025年11月04日 23:11:20 +01:00
gradlew gradle init 2025年11月04日 23:11:20 +01:00
gradlew.bat gradle init 2025年11月04日 23:11:20 +01:00
init_test_db.sh testing setup 2025年11月06日 21:51:24 +01:00
LICENSE Initial commit 2024年03月27日 15:29:09 +01:00
README.md todo/status comment 2026年05月06日 21:59:53 +02:00
settings.gradle gradle init 2025年11月04日 23:11:20 +01:00

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

  1. 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
  1. 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