https://github.com/walshydev/workerd-example
https://github.com/walshydev/workerd-example
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/walshydev/workerd-example
- Owner: WalshyDev
- License: mit
- Created: 2022-09-27T12:08:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-27T13:05:02.000Z (over 2 years ago)
- Last Synced: 2025-03-18T17:14:25.661Z (about 2 months ago)
- Language: TypeScript
- Size: 10.7 KB
- Stars: 20
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workerd Example
This is an example Worker which can be ran with workerd
This example includes bundling a Worker up and using KV (persisting to a `kv` directory)
## Running
To run simply install the dependencies and run workerd :)
Requests are served at http://localhost:8080 (can be changed in `config.capnp`)
```
# Install the dependencies (including workerd)
$ npm i# Bundle your Worker and start Workerd serving the Worker
$ npm run dev
```## Testing
Once the Worker is running we can test it!
To create a redirect do a `POST` to `/create` like so:
```
$ curl -X POST -d '{"slug": "test", "destination": "https://walshy.dev"}' http://localhost:8080/create
```Then to test the redirect simply send a `GET` request to the slug like so:
```
$ curl -i http://localhost:8080/test
HTTP/1.1 302 Found
Content-Length: 0
Location: https://walshy.dev
```