F: update readme

This commit is contained in:
aki-0421 2023-04-20 11:53:07 +09:00
parent 3d810694ca
commit 1e152e5743
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A
2 changed files with 28 additions and 13 deletions

View File

@ -28,10 +28,7 @@
- [x] Calling stubs
* [x] D1 (alpha)
* [x] Environment variables
* FetchEvent's [lifecycle methods](https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#lifecycle-methods)
- [x] waitUntil
- [ ] respondWith
- [ ] passThroughOnException
* [x] FetchEvent
## Installation

View File

@ -1,27 +1,45 @@
# fetch-event
# [FetchEvent](https://developers.cloudflare.com/workers/runtime-apis/fetch-event/)
## Document
Normally, workers are designed to return some kind of HTTP Response and exit immediately upon receiving an HTTP request. `FetchEvent` can extend these life cycles.
* https://developers.cloudflare.com/workers/runtime-apis/fetch-event/
#### WaitUntil
## Setup
`WaitUntil` extends the lifetime of the "fetch" event. It accepts an asynchronous task which the Workers runtime will execute without blocking the response. The worker will not be terminated until those tasks are completed.
#### PassThroughOnException
`PassThroughOnException` prevents a runtime error response when the Worker script throws an unhandled exception. Instead, the request forwards to the origin server as if it had not gone through the worker.
## Example
### Usecase
You have decided to implement a log stream API to capture all access logs. You must edit the Headers so that the user's API token is not logged. If an unknown error occurs during this process, the entire service will be down, which must be avoided.
In such cases, declare PassThroughOnException first and use WaitUntil for logging.
### Setup
This example worker is triggered by [Routes](https://developers.cloudflare.com/workers/platform/triggers/routes/). To try this example, add your site to cloudflare and add some records(A and CNAME, etc.) so that you can actually access the website.
If your domain is `sub.example.com`, edit `wrangler.toml` as following:
```toml
routes = [
{ pattern = "example.com/*", zone_name = "example.com" }
{ pattern = "sub.example.com/*", zone_name = "example.com" }
]
```
## Development
The workers is executed if the URL matches `sub.example.com/*`.
### Requirements
### Development
#### Requirements
This project requires these tools to be installed globally.
* wrangler
* tinygo
### Commands
#### Commands
```
make dev # run dev server