Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc/readme update #2

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,102 @@
# CF KV Workers
# CF KV Workers 🚀

Just another custom URL store made with CloudFlare Workers and KV.

## Feature Overview

- KV for Slug and Link storage
- D1 for View count tracking
- D1 for View count tracking
- Workers for Deployment

## How to use?

1. Clone the repo and head inside it
```bash
git clone https://github.com/BRAVO68WEB/url-store-kv-worker
cd url-store-kv-worker
```

2. Install all dependencies
```bash
pnpm i
```

3. Login to wrangler cli, if not done
```bash
pnpm wrangler login
```

4. Handle KV Namespace
```bash
pnpm wrangler kv:namespace create you_pref_kv_name
```

> { binding = "you_pref_kv_name", id = "xxxxxxxxxxxxxxxxxxxxxxxxxx" }

Replace existing id with this id `xxxxxxxxxxxxxxxxxxxxxxxxxx` in wrangler.toml file

```bash
pnpm wrangler kv:namespace create you_pref_kv_name_preview
```

> { binding = "you_pref_kv_name_preview", id = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" }

Replace existing preview_id with this id `yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy` in wrangler.toml file

Finally, it should look like

```toml
kv_namespaces = [
{ binding = "URLSTORE", preview_id = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", id = "xxxxxxxxxxxxxxxxxxxxxxxxxx" }
]
```

5. Handle D1 Database
```bash
pnpm wrangler d1 create you_pref_db_name
```

Output :-
```toml
[[ d1_databases ]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "you_pref_db_name"
database_id = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
```

Replace existing database_id with this id `wwwwwwwwwwwwwwwwwwwwwwwwwwwwww` in wrangler.toml file
Replace existing database_name with this id `you_pref_db_name` in wrangler.toml file

```bash
pnpm wrangler d1 create you_pref_db_name_preview
```

Output :-
```toml
[[ d1_databases ]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "you_pref_db_name_preview"
database_id = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
```

Replace existing preview_database_id with this id `wwwwwwwwwwwwwwwwwwwwwwwwwwwwww` in wrangler.toml file

6. Perform SQL table migrations

```bash
pnpm wrangler d1 execute URLSTORE --file=./schema.sql
```

7. Test locally, to see if the config works

```bash
pnpm start
```

8. Deploy to Cloudflare Workers

```bash
pnpm run deploy
```

Happy Hacking 🎉 !!
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "url-store-kv-worker",
"version": "1.0.0",
"version": "1.1.0",
"devDependencies": {
"@cloudflare/workers-types": "^3.18.0",
"better-sqlite3": "^9.6.0",
Expand Down