refactor: rename url-shortener to bit
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
# url-shortener
|
||||
# bit
|
||||
|
||||
> Lightning fast, lightweight and minimal self-hosted url shortener
|
||||
|
||||
## Benchmark
|
||||
|
||||
```shell
|
||||
./benchmark.sh
|
||||
Semaphore initialized with 2666 slots.
|
||||
Setup...
|
||||
[+] Running 1/0
|
||||
✔ Container url-shortener-app-1 Running 0.0s
|
||||
✔ Container bit-app-1 Running 0.0s
|
||||
2024-05-20T16:39:53.818306Z INFO - micrate: No migrations to run. current version: 20240513130054
|
||||
Captured API Key: 4y2mblZDneZLcI-YywHGFA
|
||||
Waiting for database to be ready...
|
||||
@@ -27,13 +29,14 @@ Accessing each link 10 times concurrently...
|
||||
Average Memory Usage: 11.00 MiB
|
||||
Average Response Time: 5.28 µs
|
||||
[+] Running 2/2
|
||||
✔ Container url-shortener-app-1 Removed 10.2s
|
||||
✔ Network url-shortener_default Removed
|
||||
✔ Container bit-app-1 Removed 10.2s
|
||||
✔ Network bit_default Removed
|
||||
```
|
||||
|
||||
## Self-hosted
|
||||
|
||||
- Run via docker-compose
|
||||
|
||||
```bash
|
||||
docker-compose up
|
||||
|
||||
@@ -42,56 +45,59 @@ docker-compose exec -it app cli --create-user=Admin
|
||||
```
|
||||
|
||||
- Run via docker cli
|
||||
|
||||
```bash
|
||||
docker run \
|
||||
--name url-shortener \
|
||||
--name bit \
|
||||
-p 4000:4000 \
|
||||
-e ENV="production" \
|
||||
-e DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&synchronous=normal&foreign_keys=true" \
|
||||
-e APP_URL="http://localhost:4000" \
|
||||
sjdonado/url-shortener
|
||||
sjdonado/bit
|
||||
|
||||
docker exec -it url-shortener migrate
|
||||
docker exec -it url-shortener cli --create-user=Admin
|
||||
docker exec -it bit migrate
|
||||
docker exec -it bit cli --create-user=Admin
|
||||
```
|
||||
|
||||
- Dokku
|
||||
|
||||
```dockerfile
|
||||
FROM sjdonado/url-shortener
|
||||
FROM sjdonado/bit
|
||||
```
|
||||
|
||||
```bash
|
||||
dokku apps:create url-shortener
|
||||
dokku apps:create bit
|
||||
|
||||
dokku domains:set url-shortener bit.donado.co
|
||||
dokku letsencrypt:enable url-shortener
|
||||
dokku domains:set bit bit.donado.co
|
||||
dokku letsencrypt:enable bit
|
||||
|
||||
dokku storage:ensure-directory url-shortener-sqlite
|
||||
dokku storage:mount url-shortener /var/lib/dokku/data/storage/url-shortener-sqlite:/usr/src/app/sqlite/
|
||||
dokku storage:ensure-directory bit-sqlite
|
||||
dokku storage:mount bit /var/lib/dokku/data/storage/bit-sqlite:/usr/src/app/sqlite/
|
||||
|
||||
dokku config:set url-shortener DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&synchronous=normal&foreign_keys=true" APP_URL=https://bit.donado.co
|
||||
dokku config:set bit DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&synchronous=normal&foreign_keys=true" APP_URL=https://bit.donado.co
|
||||
|
||||
dokku ports:add url-shortener http:80:4000
|
||||
dokku ports:add url-shortener https:443:4000
|
||||
dokku ports:add bit http:80:4000
|
||||
dokku ports:add bit https:443:4000
|
||||
|
||||
dokku run url-shortener migrate
|
||||
dokku run url-shortener cli --create-user=Admin
|
||||
dokku run bit migrate
|
||||
dokku run bit cli --create-user=Admin
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
**REST API**
|
||||
|
||||
| Endpoint | HTTP Method | Description | Payload |
|
||||
|----------|-------------|-------------|---------|
|
||||
| `/api/ping` | GET | Ping the API to check if it's running | - |
|
||||
| `/:slug` | GET | Retrieve a link by its slug | - |
|
||||
| `/api/links` | GET | Retrieve all links | - |
|
||||
| `/api/links` | POST | Create a new link | `{"url": "https://example.com"}` |
|
||||
| `/api/links/:id` | PUT | Update an existing link by its ID | `{"url": "https://newexample.com"}` |
|
||||
| `/api/links/:id` | DELETE | Delete a link by its ID | - |
|
||||
| Endpoint | HTTP Method | Description | Payload |
|
||||
| ---------------- | ----------- | ------------------------------------- | ----------------------------------- |
|
||||
| `/api/ping` | GET | Ping the API to check if it's running | - |
|
||||
| `/:slug` | GET | Retrieve a link by its slug | - |
|
||||
| `/api/links` | GET | Retrieve all links | - |
|
||||
| `/api/links` | POST | Create a new link | `{"url": "https://example.com"}` |
|
||||
| `/api/links/:id` | PUT | Update an existing link by its ID | `{"url": "https://newexample.com"}` |
|
||||
| `/api/links/:id` | DELETE | Delete a link by its ID | - |
|
||||
|
||||
**CLI**
|
||||
|
||||
```
|
||||
Usage: ./cli [options]
|
||||
Options:
|
||||
@@ -111,7 +117,7 @@ brew install micrate
|
||||
|
||||
```bash
|
||||
shards run migrate
|
||||
shards run url-shortener
|
||||
shards run bit
|
||||
```
|
||||
|
||||
**Generate the `X-Api-Key`**
|
||||
@@ -121,13 +127,14 @@ shards run cli -- --create-user=Admin
|
||||
```
|
||||
|
||||
## Run tests
|
||||
|
||||
```bash
|
||||
ENV=test crystal spec
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it (<https://github.com/sjdonado/url-shortener/fork>)
|
||||
1. Fork it (<https://github.com/sjdonado/bit/fork>)
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
|
||||
Reference in New Issue
Block a user