https://github.com/ecmadao/minishcap-service
A short link service
https://github.com/ecmadao/minishcap-service
koa2 nodejs typescript
Last synced: 10 months ago
JSON representation
A short link service
- Host: GitHub
- URL: https://github.com/ecmadao/minishcap-service
- Owner: ecmadao
- Created: 2021-11-21T04:26:36.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-12T04:04:43.000Z (over 3 years ago)
- Last Synced: 2025-01-23T13:27:43.915Z (12 months ago)
- Topics: koa2, nodejs, typescript
- Language: TypeScript
- Homepage: https://ecmadao.github.io/minishcap-demo/
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minishcap Service
A short link service
## Prerequisites
- MongoDB
- Redis
- Node
## Develop
### Docker
One command through docker
```bash
$ git clone https://github.com/ecmadao/minishcap-service.git
$ cd minishcap-service
$ docker-compose up
```
### Classic
#### Step 1
```bash
$ git clone https://github.com/ecmadao/minishcap-service.git
$ cd minishcap-service
$ npm i
```
#### Step 2
- Ensure your MongoDB and Redis service is running
- Check the DB storage configuration is correct in `src/config/env/development.yaml` file
- By default, we will use 27017 port for MongoDB and 6379 port for Redis in localhost
#### Step 3
```bash
$ npm run start-dev
# Then open browser with URL http://localhost:3334/api/v1/
```
## APIs
### Generate short link
Request:
```bash
POST /api/v1/urls
```
Body:
```json
{
"urls": [
{
"url": "your URL here",
"ttlInSeconds": 60 // Time to live in seconds. Set anything < 0 (like -1) if it has no expire time
}
]
}
```
Response:
```json
{
"success": true,
"result": [
{
"short": "the short url",
"raw": "the raw url",
"expiredAt": "expiration datetime"
}
]
}
```
## Deploy
### Prerequisites
Check your configuration in production: `./src/config/env/production.yaml`
### Scheduler
I also build a scheduler to free expired short ids, release them into Redis set.
Thus, everytime before we need to create a new short id, we can check if can use the old one.
You can find the scheduler here: [minishcap-scheduler](https://github.com/ecmadao/minishcap-scheduler), written in pure TypeScript.
Hint: It's totally okay not use the scheduler in your project.