An open API service indexing awesome lists of open source software.

https://github.com/blooym/workerlink

[Mirror] Serverless link shortener for Cloudflare Workers & KV.
https://github.com/blooym/workerlink

cloudflare-kv cloudflare-workers link-shortener

Last synced: 6 days ago
JSON representation

[Mirror] Serverless link shortener for Cloudflare Workers & KV.

Awesome Lists containing this project

README

          

# Workerlink

A serverless URL shortener built on Cloudflare Workers & Cloudflare KV.

## Deployment

In order to deploy workerlink to Cloudflare Workers, you need to do the following:

1. Clone this repository locally with git or by downloading the source archive.
2. Download and install [NodeJS](https://nodejs.org) and [Rust v1.85.0+](https://rustup.rs/), or use the provided [.devcontainer](.devcontainer) setup for an environment.
3. Run `npm install` to install all dependencies needed to build/deploy.
4. [Setup a KV namespace](https://developers.cloudflare.com/kv/get-started/) on Cloudflare by following their documentation.
5. Create a 'wrangler.toml' file with the following contents at the root of the repository:
```toml
name = "workerlink"
main = "build/worker/shim.mjs"
compatibility_date = "2024-11-11"
kv_namespaces = [
{ binding = "links", id = "" } # Replace with the ID of the KV namespace you setup earlier.
]

[vars]
AUTH_TOKEN = "" # Set this to the token you want to use for authentication.

[build]
command = "cargo install -q worker-build && worker-build --release"
```
6. Run `npm run deploy` to deploy the worker to Cloudflare; You will be prompted to authenticate with Cloudflare during this process so the worker can be deployed using your account.

## Examples

- **In a browser:** Use a redirect.
Navigate to `https:///` and the browser will automatically direct.

- **In a browser:** See where an ID redirects to.
Navigate to `https:////where` and the redirect url will be shown in plaintext.

- **Using curl:** Create/Update a new redirect.
```bash
curl --request POST \
--url 'https:///' \
--header 'Authorization: ' \
--header 'content-type: application/json' \
--data '{
"url": "",
"expiry_timestamp": unix_timestamp | null,
"max_views": number | null,
"overwrite": boolean,
"disabled": boolean
}'
```

- **Using curl:** Delete an existing redirect.
```bash
curl --request DELETE \
--url 'https:///' \
--header 'Authorization: '
```

- **Using curl:** Check the underlying JSON of a redirect.
```bash
curl 'https:////details' \
--header 'Authorization: '
```

## License

This project is dual-licensed under both the MIT License and the Apache License (Version 2.0). See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE) for more details.