A simple Cloudflare worker with Netacea built in.
This template is meant to be used with Wrangler. If you are not already familiar with the tool, we recommend that you install the tool and configure it to work with your Cloudflare account.
Node version 20
or later and npm version 10
or later is required.
To generate using Wrangler, run this command:
wrangler generate netacea-cloudflare-worker https://github.com/netacea/cloudflare-worker-template-typescript
Ensure the @netacea/cloudflare
package is up to date by running:
npm i @netacea/cloudflare@latest
- Ensure you are logged into Wrangler.
- Insert your wrangler credentials into the
wrangler.toml
file in the root directory (you only need to changeaccount_id
,route
, andcompatibility_date
- the rest is okay).
Configuration of the integration can be performed in the NetaceaConfig.json
file, in the ./src
directory.
Here you can find several parameters which need to be properly configured:
apiKey
- the API key for your domain. Provided by Netacea. Used to communicate with the Mitigation and Ingest APIs.secretKey
- the Secret key for your domain. Provided by Netacea. Used to check the authenticity of cookies.mitigationType
- either "INGEST" or "MITIGATE" to disable / enable mitigation, respectively.cookieEncryptionKey
- used to encrypt cookie data. Can be provided by either the customer, or Netacea.netaceaCookieName
- name of the Netacea cookie. Name should set so as not to conflict with existing cookies on site.netaceaCaptchaCookieName
- name of the Netacea captcha cookie. Name should set so as not to conflict with existing cookies on site.timeout
(optional) - the number of milliseconds to wait for a response from the Mitigation API before proceeding to the origin website. Default 3000ms.
If you need to extend or enhance the functionality of the Cloudflare Worker, the documentation can be found here.
Code extensions should be made in ./src/handler.ts
Please ensure that worker.run(event, originRequest)
and event.waitUntil(worker.ingest(event.request, response))
are called.
npm run test
- This will run a set of simple method tests against the worker (see./tests/handler.test.ts
)npm run dev
- alias forwrangler dev
- documentation.npm run dev:local
- alias forwrangler dev --local
- live preview of your code in a cloudflare sandbox - accessible from only your machine.
The integration must be built with webpack before deployment via wrangler.
You can do this yourself by running npm run build
, or use npm run deploy
to build with webpack and publish to your Cloudflare distribution in one command.
If you run into issues with this specific project, please feel free to file an issue here. If the problem is with Wrangler, please file an issue here.