Skip to content

Commit 1ac79ad

Browse files
committed
add guide for upgrading from v5 to v6
1 parent 55cab83 commit 1ac79ad

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Netacea Cloudflare Worker Template
2+
23
![Netacea Header](https://assets.ntcacdn.net/header.jpg)
34
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
45

@@ -32,12 +33,22 @@ Here you can find several parameters which need to be properly configured:
3233
- `netaceaCaptchaCookieName` - name of the Netacea captcha cookie. Name should set so as not to conflict with existing cookies on site.
3334
- `timeout` (optional) - the number of milliseconds to wait for a response from the Mitigation API before proceeding to the origin website. Default 3000ms.
3435

36+
## ⬆️ Upgrading
37+
38+
If you're upgrading from a previous version of the Netacea Cloudflare Worker Template,
39+
most of the time you should be able to upgrade by running `npm install --save @netacea/cloudflare@latest`.
40+
41+
However, if you are upgrading from v6 to v5, then please see the
42+
[v5 to v6 upgrade guide.](./docs/upgrading_v5_to_v6.md)
43+
3544
## 💻 Development
45+
3646
If you need to extend or enhance the functionality of the Cloudflare Worker, the documentation can be found [here](https://developers.cloudflare.com/workers/).
3747
Code extensions should be made in `./src/handler.ts`
3848
Please ensure that `worker.run(event, originRequest)` and `event.waitUntil(worker.ingest(event.request, response))` are called.
3949

4050
## ✔ Testing
51+
4152
- `npm run test` - This will run a set of simple method tests against the worker (see `./tests/handler.test.ts`)
4253
- `npm run dev` - alias for `wrangler dev` - [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#dev).
4354
- `npm run dev:local` - alias for `wrangler dev --local` - live preview of your code in a cloudflare sandbox - accessible from only your machine.
@@ -49,4 +60,5 @@ You can do this yourself by running `npm run build`, or use `npm run deploy`
4960
to build with webpack and publish to your Cloudflare distribution in one command.
5061

5162
## ❗ Issues
63+
5264
If you run into issues with this specific project, please feel free to file an issue [here](https://github.com/Netacea/cloudflare-worker-template-typescript/issues). If the problem is with Wrangler, please file an issue [here](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler).

docs/upgrading_v5_to_v6.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# ⬆ Netacea Cloudflare v5 to v6 Upgrade Guide
2+
3+
This template has been updated to support the **v6** release of `@netacea/cloudflare`.
4+
This version introduces changes to the interface,
5+
requiring updates to how the module is integrated within the cloudflare handler.
6+
7+
This guide walks you through the required changes and best practices when using v6.
8+
9+
You can install v6 using `npm install --save @netacea/cloudflare@6`
10+
11+
## 📦 What's New in v6?
12+
13+
The `run` method now returns a result object with a `response` property, rather than returning a `Response` directly.
14+
This change allows for greater extensibility in the result metadata.
15+
16+
### Old Usage (v5)
17+
18+
```ts
19+
const response = await worker.run(event, originRequest)
20+
event.waitUntil(worker.ingest(event.request, response))
21+
return response
22+
```
23+
24+
### New Usage (v6)
25+
26+
```ts
27+
const result = await worker.run(event, originRequest)
28+
event.waitUntil(worker.ingest(event.request, result))
29+
return result.response
30+
```
31+
32+
---
33+
34+
## 🔧 Code Changes
35+
36+
### Updated Handler
37+
38+
Once updated, your handler should look something like:
39+
40+
```ts
41+
import { Cloudflare } from '@netacea/cloudflare'
42+
43+
const worker = new Cloudflare(NetaceaConfig)
44+
45+
export async function handleRequestWithNetacea(event: FetchEvent): Promise<Response> {
46+
const result = await worker.run(event, originRequest)
47+
event.waitUntil(worker.ingest(event.request, result))
48+
return result.response
49+
}
50+
51+
async function originRequest(request: Request): Promise<Response> {
52+
// Your origin logic here
53+
}
54+
```
55+
56+
### Updated Tests
57+
58+
The `run` method must now return an object with a `response` property in your mocks:
59+
60+
```ts
61+
const { handleRequestWithNetacea } = proxyquire('../src/handler', {
62+
'@netacea/cloudflare': function () {
63+
return {
64+
run: () => ({
65+
response: new Response()
66+
}),
67+
ingest: () => {
68+
// no-op
69+
}
70+
}
71+
}
72+
})
73+
```
74+
75+
Also, ensure your test requests include a fully qualified URL
76+
(e.g., `https://example.com`) to avoid errors when constructing `Request` objects.
77+
78+
---
79+
80+
## ✅ Summary of Required Changes
81+
82+
| Area | Change |
83+
|-------------|--------------------------------------------------|
84+
| `run()` usage | Use `result.response` instead of `response` |
85+
| `ingest()` | Pass the full `result` to `ingest()` |
86+
| Tests | Update mocks to return `{ response: Response }` |

0 commit comments

Comments
 (0)