mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
F: update readme
This commit is contained in:
parent
3d810694ca
commit
1e152e5743
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user