Skip to content

somespecialone/likes-counter

Repository files navigation

Likes Counter

Likes Views Made in Ukraine license code style: prettier Test Deploy Demo codecov

An easy-to-integrate like counter for your website.

Install on Space

Note

Try demo here. Also look at the singling views-counter

API of the app is available at address: https://lc.somespecial.one. But please, if you tend to use it heavily, consider to installing the app on Deta Space by yourself with button above!

How to use

App exposes json API routes.

Generate route

Generate unique user id, if you don't want ot make it by yourself on client side.

Have len query param - length of generated id. Default len value is 10.

GET /generate

{
  "id": "generated id"
}

Like routes

  • slug - unique key for page/post/etc.
  • userId - unique user id. Can be generated in /generate route.

GET :slug/:userId

{
  "userLikes": 0,
  "totalLikes": 0
}

POST :slug/:userId

Payload (body) must be JSON and contain count field. For example:

{
  "count": 1
}

Response is null

Maximum likes number

By default, the maximum number of the likes is limited to 1. To set your own option you can add ::{your max likes number} postfix to slug. For example super-unique-slug::10 will set max number to 10 for the current route.

App can use NITRO_DEF_MAX_LIKES_COUNT env variable to set default number, know more

Deployment βš’οΈ

Deta Space πŸš€πŸŒŒ

You can install app on Deta Space with button above.

Providers

If this is not an option for you, application code can be built for these providers, so just clone the repo and use your provider.

Env variables

App use Deta Base for database, so DETA_PROJECT_KEY or NITRO_DETA_PROJECT_KEY are required.

  • DETA_PROJECT_KEY/NITRO_DETA_PROJECT_KEY - deta project key, required if app installed not in Deta Space. Read more there
  • NITRO_DEF_MAX_LIKES_COUNT - max number of likes. Default 1
  • NITRO_DEF_ID_LENGTH - length of generated id. Default 10
  • NITRO_ALLOW_ORIGIN - allow origin header. Default *

Tests πŸ§ͺ

Clone repo and run test script with your package manager or

vitest