项目作者: glosa

项目描述 :
Comments for static sites. Clone of Disqus, but faster, Opensource and sexy.
高级语言: HTML
项目地址: git://github.com/glosa/glosa-server.git
创建时间: 2020-03-04T17:40:40Z
项目社区:https://github.com/glosa/glosa-server

开源协议:Apache License 2.0

下载



logo


Glosa: Comments for static sites.



Clone of Disqus, but faster, Opensource and sexy.

No Maintenance Intended

Amazing reasons to use it

  • Opensource.
  • Very fast, responses between 5ms and 15ms on average.
  • Easy to integrate with static pages.
  • PWA Admin for desktop and mobile or terminal to manage comments: Delete, update, find…
  • Easy to import from Disqus.
  • No database, everything is stored in a JSON.
  • Configuration in a simple YAML.
  • Captcha system included.
  • Receive an email for each new comment.
  • Users are notified by email if they are answered.
  • Multisite: Single server for multiple websites.

Resources

Template static site (only HTML and Javascript)

Import your comments from Disqus

PWA Admin

Video Demo


Help me continue to improve


Buy Me a Coffee at ko-fi.com

—-

## Use it now

- How does it work?
- Origin
- Run
- Notification template for email
- API
- Terminal cli
- Deployment
- Create your own JAR

—-

## How does it work?


logo

On the one hand we have Glosa who would be our comment server. It feeds in GET and POST requests, and obediently returns JSON. It can only return comments from a url (it sorts comments by url, not ids) or create a new comment (parent or child of another comment). Nothing else. If you want to create a comment previously you will need to ask for the token to confirm that you are not a robot.

Optionally you can receive an email automatically when a new comment is written.

The website, CMS or mobile application, must integrate a logic with Javascript to make the necessary requests and render the comments properly. To make this task easier we have created an example template that you can modify to your needs. You can find the link on this page.

Scenarios

1 web page, share or not a server


logo

3 web pages in different domains or servers


logo

Origin

A Glosa is a Spanish word. It is defined as a note, usually brief, that is written in the margin of a text or even between its lines with the intention of clarifying some idea of it.

The software was born with the intention that the author’s static blog would no longer depend on an external company (Disqus), and could have control of its content. To make it as easy as possible to deploy, develop and maintain; he programmed in Clojure. And from the beginning it was clear to him that he didn’t need a conventional database, plain text was enough.

Run

1) Make sure you have Java installed.

Debian/Ubuntu

  1. sudo apt install default-jre

Mac OS

  1. brew install java

2) Create a file config.yaml with the following content. You can also use config.yaml.example as a base config and change it to fit your needs.

  1. ##### General #####
  2. # If it is active it will be accessible to any client
  3. debug: false
  4. # It can be a domain in case of using a proxy: example.com
  5. domain: localhost
  6. port: 4000
  7. # Access for APP
  8. token: mysecret
  9. # It indicates which domain can use it. Debug true so there are no limitations.
  10. domain-cli: "http://example-cli.com/"
  11. ##### Notify #####
  12. # Type of notification, currently valid: email
  13. notify: email
  14. subject: New comment
  15. from: server@example.com
  16. admin: user@example.com
  17. # SMTP, only notify: email
  18. smtp-host: smtp.example.com
  19. smtp-user: smtpuser
  20. smtp-password: smtppassword
  21. smtp-port: 25
  22. smtp-tls: true
  23. ##### Captcha #####
  24. # Currently valid: time
  25. captcha: time
  26. ##### Database #####
  27. # Currently valid: plain
  28. database: plain

3) Download the latest version of Glosa (glosa-{version}-standalone.jar).

https://github.com/glosa/glosa-server/releases

4) Now you can execute glosa.

  1. java -jar target/glosa-{version}-standalone.jar

Great 🎉. You already have your 🔥 own comment server 🔥.

That’s it, now you just have to test that it works properly.

  1. curl localhost:4000/api/v1/captcha/?url=https://glosa.example/best-SO/'

It will return a random token

  1. {"token":"OABWNONEOOKXRMMWADPF"}

Notification template for email

The first time Glosa is run it will create an HTML template with the name template-email.html. Edit freely.


logo


API

Authorization

Only privates.

You need a token to be able to interact (You will find it in your config.yaml). Use a header with Bearer authorization on each request.

Example with mysecret token.

  1. curl -XDELETE -H "Authorization: Bearer mysecret" -H "Content-type: application/json" ...

Public

No token is required to interact.

Get Comments

Gets all the comments on one page.

Method: GET

  1. /api/v1/comments/?url={url}
Param Value Description
url string Page where you want to get the comments.
Example

Get from http://glosa.example/best-SO/.

  1. curl 'http://localhost:4000/api/v1/comments/?url=https://glosa.example/best-SO/'
Success response
  1. [
  2. {
  3. "id": 4812781236,
  4. "parent": "",
  5. "deep": 0,
  6. "createdAt": 1584266634,
  7. "thread": "https://glosa.example/best-SO/",
  8. "author": "Lexar",
  9. "email": "",
  10. "message": "Do you use Glosa too? It's an amazing technology."
  11. },
  12. {
  13. "id": 4812781237,
  14. "parent": "4812781236",
  15. "deep": 1,
  16. "createdAt": 1584266746,
  17. "thread": "https://glosa.example/best-SO/",
  18. "author": "Lucia",
  19. "email": "lucia@my.email",
  20. "message": "I love the article."
  21. }
  22. ]
Fail response
  1. []

Last Comments

Get the last 10 comments sorted by date. A pager is available.

Method: POST

  1. /api/v1/comments/latest/{page}
Param Value Description
page number Paginator.
Example

I get the last 10 comments.

  1. curl 'http://localhost:4000/api/v1/comments/latest/1'

Last comments between 30 and 40.

  1. curl 'http://localhost:4000/api/v1/comments/latest/3'
Success response
  1. [
  2. {
  3. "id": 4812781236,
  4. "parent": "",
  5. "deep": 0,
  6. "createdAt": 1584266634,
  7. "thread": "https://glosa.example/best-SO/",
  8. "author": "Lexar",
  9. "email": "",
  10. "message": "Do you use Glosa too? It's an amazing technology."
  11. },
  12. {
  13. "id": 4812781237,
  14. "parent": "4812781236",
  15. "deep": 1,
  16. "createdAt": 1584266746,
  17. "thread": "https://glosa.example/best-SO/",
  18. "author": "Lucia",
  19. "email": "lucia@my.email",
  20. "message": "I love the article."
  21. }
  22. ...
  23. ]
Fail response
  1. []

Add Comment

Add new comment on one page. Require token generated by the captcha endpoint. After saving the comment the captcha token will no longer be valid. At the same time a notification (email) will be sent to the administrator (in the configuration it is called admin), in case it is a sub-comment it will also be sent another notification to the parent of the comment if the address is present.

The steps must be.

  1. Get captcha token.
  2. Add comment.

Method: POST

  1. /api/v1/comments/
Param Value Description
parent number If it’s a sub-comment, the number of the parent comment. Otherwise leave empty.
author string Author’s name.
email string Email that the user will be notified of the responses to his comment. Leave blank if not desired.
message string Message. It can be HTML or plain.
token number Number of the token generated by the captcha endpoint.
thread string Page where you want to save the comment.
Example

Save comment from https://glosa.example/best-SO/.

  1. curl -XPOST -H "Content-type: application/json" -d '{
  2. "parent": "",
  3. "token": "VRJUOBBMTKFQUAFZOKJG",
  4. "author": "Juana",
  5. "email": "juana@my.email",
  6. "message": "I like it very much.",
  7. "thread":"https://glosa.example/best-SO/"
  8. }' 'http://localhost:4000/api/v1/comments/'
Success response
  1. {
  2. "added": true
  3. }
Fail response
  1. {
  2. "added": false
  3. }

Get captcha token

Get a token to validate that a new comment can be created. It has only one use. It must also be obtained 20 seconds before use or it will not work.

Method: GET

  1. /api/v1/captcha/?url={url}
Param Value Description
url string Page where you want to save the comment.
Example

Get token for page https://glosa.example/best-SO/.

  1. curl 'http://localhost:4000/api/v1/captcha/?url=https://glosa.example/best-SO/'
Success response
  1. {
  2. "token": "ZRFOKXLALKNPOJPYJLVY"
  3. }
Fail response
  1. {
  2. "error": "Need URL"
  3. }

Check if he is alive

Simple answer to check that the service is working.

Method: GET

  1. /api/v1/ping/
Example
  1. curl 'http://localhost:4000/api/v1/ping/'
Success response
  1. {
  2. "ping": "pong"
  3. }

Check if token is valid

Method: POST

  1. /api/v1/token/check/
Param Value Description
url string Page where you want to save the comment.
Example
  1. curl -XPOST -H "Authorization: Bearer mysecret" 'http://localhost:4000/api/v1/token/check/'
Success response
  1. {
  2. "valid": true
  3. }
Fail response
  1. {
  2. "valid": false
  3. }

Private

Update Comment

Update a comment for ID. Authorization required.

Method: PUT

  1. /api/v1/comments/
Param Value Description
id number Comment ID.
author string Author’s name.
email string Email that the user will be notified of the responses to his comment. Leave blank if not desired.
message string Message. It can be HTML or plain.
Example

Update comment with id 1234.

  1. curl -XPUT -H "Authorization: Bearer mysecret" -H "Content-type: application/json" -d '{
  2. "id": 1234
  3. "author": "Alex",
  4. "email": "alex@my.email",
  5. "message": "I love the article."
  6. }' 'http://localhost:4000/api/v1/comments/
Success response
  1. {
  2. "updated": true,
  3. "id": 1234
  4. }
Fail response
  1. {
  2. "updated": false,
  3. "id": 1234
  4. }

Delete Comment

Delete a comment for ID. Authorization required.

Method: DELETE

  1. /api/v1/comments/{id}
Param Value Description
id number Comment ID.
Example

Delete comment with id 1234.

  1. curl -XDELETE -H "Authorization: Bearer mysecret" -H "Content-type: application/json" http://localhost:4000/api/v1/comments/1234
Success response
  1. {
  2. "deleted": true,
  3. "id": 1234
  4. }
Fail response
  1. {
  2. "deleted": false,
  3. "id": 1234
  4. }

Search Threads

Search for all urls containing a certain string ignoring uppercase. Authorization required.

Method: POST

  1. /api/v1/threads/search/{query}
Param Value Description
query string String to search.
Example

Search all threads with tadam.

  1. curl -XPOST -H "Authorization: Bearer mysecret" 'http://localhost:4000/api/v1/threads/search/tadam'
Success response
  1. [
  2. {
  3. "thread": "https://my.blog/tadam-vs-pedestal/"
  4. },
  5. {
  6. "thread": "https://my.blog/best-web-framework-clojure-tadam"
  7. }
  8. ]
Fail response
  1. []

Terminal cli

To manage some minor features you can use the manager script which will filter, modify or delete the database. Previously remember to stop Glosa to avoid problems.

You will need to have Node installed on your computer and give it permission to run.

Last comments

  1. ./manager last [number of elements]

Example

  1. ./manager last 3

Take all comments by thread

  1. ./manager get [thread]

Example

  1. ./manager get https://glosa.example/best-SO/

Update the text of a comment

  1. ./manager update [id] [new message]

Example

  1. ./manager update 1234 'I love your article.'

Delete a comment

  1. ./manager delete [id]

Example

  1. ./manager delete 1234

Deployment

With Nginx it’s pretty quick and easy. You can use it as a reverse proxy, since Glosa contains its own web server (Jetty). You can see an example of configuration that can be useful.

Nginx

  1. server {
  2. server_name glosa.domain.com;
  3. access_log /var/log/glosa_access.log;
  4. error_log /var/log/glosa_error.log;
  5. location / {
  6. proxy_pass http://localhost:4000/;
  7. proxy_set_header Host $http_host;
  8. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  9. proxy_set_header X-Forwarded-Proto $scheme;
  10. proxy_redirect off;
  11. }
  12. }

Systemctl

To create a service in Linux is done like any application in Java. Below you can see an example.

Create a file in the following path: /etc/systemd/system/glosa.service

Add the content.

  1. [Unit]
  2. Description=Glosa
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. Restart=always
  7. WorkingDirectory=/folder/jar/
  8. ExecStart=java -jar glosa.jar
  9. [Install]
  10. WantedBy=multi-user.target

Finally enable and start the service.

  1. sudo systemctl enable glosa
  2. sudo systemctl start glosa

Create your own JAR

1) Make sure you have openjdk or oracle-jdk installed, clojure and leiningen.

MacOS

  1. brew install openjdk clojure leiningen

Debian/Ubuntu

  1. sudo apt install default-jdk clojure leiningen

2) Clone the repository and enter the generated folder.

  1. git clone https://github.com/glosa/glosa-server.git
  2. cd glosa-server

3) Run the following command to build a jar file.

lein uberjar

After this two files should be created in target/. We will use the standalone version: glosa-{version}-standalone.jar.


Dev tools

It needs to be executed at the root of the project and have Leiningen installed.

Lint

It checks linguistically and syntaxically if the code is correct.

  1. make lint

Build

Build a JAR ready to distribute.

  1. make build

Deploy

Distributed in Clojars.

  1. make deploy


Thanks to the power of logo Tadam Framework