-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return shortened url on create + sqlite viewer (#6)
- Loading branch information
Showing
5 changed files
with
143 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,82 @@ | ||
# URL Shortener - Cloudflare Worker | ||
|
||
## Usage | ||
## Development | ||
|
||
### Prerequisites | ||
|
||
You have two options: | ||
|
||
Option one (recommended): | ||
|
||
- [install](https://devenv.sh/getting-started/) `devenv` && run `devenv up` | ||
- done. | ||
|
||
Now you can run `dev`, `fmt`, etc. (tasks are defined in [`tasks.nix`](./tasks.nix)) | ||
|
||
Option two: follow Cloudflare's [guide](https://developers.cloudflare.com/workers/languages/rust/) | ||
|
||
- [install `Node.js`](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) | ||
- [install `wrangler`](https://bun.sh/docs/installation) | ||
- [install `rust`](https://www.rust-lang.org/tools/install) | ||
|
||
> [!NOTE] | ||
> When running locally use `http://localhost:8787` | ||
> the rest of the guide assumes you're using `devenv` | ||
> | ||
> if you're installing stuff manully, | ||
> take a look at [`tasks.nix`](./tasks.nix) for the commands | ||
### Shorten a URL | ||
Once you've installed the prerequisites, you can run: | ||
|
||
dev server | ||
|
||
```bash | ||
dev | ||
``` | ||
|
||
rowser-based sqlite viewer | ||
|
||
```bash | ||
d1-viewer | ||
``` | ||
|
||
seed local d1 database with data | ||
|
||
```bash | ||
wrangler dev --config='wrangler.toml' dev --preview | ||
d1-seed | ||
``` | ||
|
||
shorten a URL | ||
|
||
```bash | ||
curl --url http://localhost:8787/create \ | ||
--request 'POST' \ | ||
--data-binary 'https://docs.union.build/reference/graphql/?query=%7B%20__typename%20%7D' | ||
``` | ||
|
||
now refresh the d1 viewer page and you should see the new record | ||
|
||
## Usage | ||
|
||
> [!NOTE] | ||
> When running locally use `http://localhost:8787` | ||
### Shorten a URL | ||
|
||
```bash | ||
curl --url http://localhost:8787/create \ | ||
--request 'POST' \ | ||
--data-binary 'https://docs.union.build/reference/graphql/?query=%7B%20__typename%20%7D' | ||
``` | ||
|
||
This will return a short id, for example: | ||
This will return a short the shortened URL, for example: | ||
|
||
```sh | ||
7312a5 | ||
# example | ||
https://localhost/26 | ||
``` | ||
|
||
### Expand a short URL | ||
|
||
```bash | ||
curl --url http://localhost:8787/7312a5 | ||
curl --url http://localhost:8787/26 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters