https://github.com/somespecialone/likes-counter
๐ An easy-to-integrate like counter for your website
https://github.com/somespecialone/likes-counter
deta nitro serverless typescript vitest web
Last synced: 8 months ago
JSON representation
๐ An easy-to-integrate like counter for your website
- Host: GitHub
- URL: https://github.com/somespecialone/likes-counter
- Owner: somespecialone
- License: mit
- Created: 2023-09-05T10:41:15.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-21T11:20:06.000Z (over 1 year ago)
- Last Synced: 2024-07-30T18:05:08.577Z (12 months ago)
- Topics: deta, nitro, serverless, typescript, vitest, web
- Language: TypeScript
- Homepage: https://somespecialone.github.io/likes-counter/
- Size: 562 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Likes Counter
[](https://lc.somespecial.one)
[](https://github.com/somespecialone/views-counter)
[](https://stand-with-ukraine.pp.ua)
[](https://github.com/somespecialone/likes-counter/blob/master/LICENSE)
[](https://github.com/prettier/prettier)
[](https://github.com/somespecialone/likes-counter/actions/workflows/tests.yml)
[](https://github.com/somespecialone/likes-counter/actions/workflows/deploy.yml)
[](https://github.com/somespecialone/likes-counter/actions/workflows/demo.yml)
[](https://codecov.io/gh/somespecialone/likes-counter)An easy-to-integrate like counter for your website.
[](https://deta.space/discovery/@somespecialone/likescounter)
> [!NOTE]
> Try demo **[here](https://somespecialone.github.io/likes-counter)**. Also look
> at the singling [views-counter](https://github.com/somespecialone/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`
```json
{
"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`
```json
{
"userLikes": 0,
"totalLikes": 0
}
```> POST `:slug/:userId`
Payload (body) must be JSON and contain `count` field. For example:
```json
{
"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-)
## 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](https://nitro.unjs.io/deploy), 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](https://deta.space/docs/en/use/your-data/collections#data-keys)
* `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
```sh
vitest
```