# Installation via Wrangler (CLI)

### Prerequisites

To successfully integrate using Netacea, please ensure you have:

1. Installed latest [Wrangler V2](https://developers.cloudflare.com/workers/wrangler/migration/v1-to-v2/update-v1-to-v2/), [Node.js](https://nodejs.org/en) (version 16.13.0 or higher) and [Git ](https://git-scm.com/)on you machine.
2. An active Cloudflare account with access to the Cloudflare Dashboard.
3. A “Paid” Cloudflare subscription, in order to avoid any issues with worker request-limits etc.
4. Access to the Cloudflare Workers product.

### **Implementation Steps**

The detailed GitHub instructions to pull the code, configure and deploy the Netacea Cloudflare plugin can be found [here](https://github.com/Netacea/cloudflare-worker-template-typescript).

### Create local worker <a href="#edit-worker" id="edit-worker"></a>

Open Windows Command-Prompt/PowerShell and navigate to a directory where you can save the Netacea code.

Within that directory execute the following command

{% code overflow="wrap" %}

```
wrangler generate netacea-cloudflare-worker https://github.com/netacea/cloudflare-worker-template-typescript
```

{% endcode %}

This will use wrangler to create (generate) a new local worker bundle by pulling the latest Netacea GitHub code.

<figure><img src="/files/gZv7axZr8wz21X4gFPYZ" alt=""><figcaption></figcaption></figure>

You can verify this by visiting the above directory and seeing the worker with the following format:

<div align="left"><figure><img src="/files/75HEL7tAd6bDR8pYRg1O" alt=""><figcaption></figcaption></figure></div>

### Configure the worker

Open the src directory and edit the `NetaceaConfig.json` file to match the below:

```json
{
    "apiKey": "API-KEY-PROVIDED-BY-NETACEA",
    "secretKey": "SECRET-KEY-PROVIDED-BY-NETACEA",
    "mitigationType": "PREFERRED-MITIGATION-TYPE",
    "ingestType": "KINESIS",
    "kinesis": {
      "kinesisStreamName": "NAME-PROVIDED-BY-NETACEA",
      "kinesisAccessKey": "KEY-PROVIDED-BY-NETACEA",
      "kinesisSecretKey": "KEY-PROVIDED-BY-NETACEA"
    },
    "cookieEncryptionKey": "ENCRYPTION-KEY-PROVIDED-BY-NETACEA",
    "netaceaCookieName": "_cookieName",
    "netaceaCaptchaCookieName": "_captchaCookieName",
    "enableDynamicCaptchaContentType": false,
    "timeout": 3000
  }
```

Replace the values with the details that Netacea has provided you and **save** the file.

{% hint style="info" %}
The attribute `mitigationType` is used to determine the mode of the integration. This can be one of three values:

* "**INGEST**" - This integration mode is monitoring only, meaning that no mitigation actions will be executed. This is recommended during POCs.
* "**MITIGATE**" - This is the "normal" integration mode, meaning that the Netacea solution will monitor and actively mitigate requests.
* "**INJECT**" - This mode is used in custom solutions in which the mitigation action by Netacea will only be a recommendation using HTTP headers added to the request.
  {% endhint %}

{% hint style="info" %}
The cookie and captcha name should be unique.

**For added security, do not include Netacea or Mitigation in this name.**
{% endhint %}

{% hint style="danger" %}
The cookieEncryptionKey, netaceaCookieName and netaceaCaptchaCookieName variables are used to increase security by concealing Netacea's default cookie names and values from public view.
{% endhint %}

### Configure Wrangler

Navigate to the worker's root directory and edit the `wrangler.toml` file:

```json
name = "netacea-worker"
main = "./dist/worker.js"

account_id = "EXAMPLE_ACCOUNT_ID"
route = "EXAMPLE_ROUTE"

compatibility_date = "2023-05-04"

[observability]
enabled = true

```

Replace the values with the appropriate details and Once ready, **save** the file.

{% hint style="info" %}
The [Account ID](https://developers.cloudflare.com/fundamentals/get-started/basic-tasks/find-account-and-zone-ids/#find-zone-and-account-ids) can be found on your Cloudflare Dashboard.

The [Route ](https://developers.cloudflare.com/workers/platform/triggers/routes/)refers to the path that the worker should be applied to, e.g. "[www.example.com/\*](http://www.example.com/*)" and can be edited after deployment.
{% endhint %}

{% hint style="info" %}
Enabling the **Auto Save** option while changing configurations would be helpful.
{% endhint %}

![](/files/iMzvL5mtWuqAwsGu4xmd)

### Install/Update npm

Within the worker root directory, execute the following two commands to ensure all the necessary node modules are installed/updated

```powershell
npm i @netacea/cloudflare@latest
```

```
npm install
```

### Deploy the worker to Cloudflare

Execute the following command:

```
npm run deploy
```

This might prompt you to login to Cloudflare via your browser and allow access to wrangler. If so, login and allow access.

<div align="left"><figure><img src="/files/1ChAw6PiH9eOJVH4WvRF" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/6l16VsZIdmTvYDvNnxmh" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can use the above command to re-deploy the same worker in order to update it (e.g. changing the configuration properties). The last deployment will become active by default.
{% endhint %}

### Confirm Deployment

Login to Cloudflare, open the dashboard, select the domain where you want the worker to work on and finally select "Workers Routes" from the menu. You should be able to see the newly deployed worker, associated with the route from the `wrangler.toml` file.

<figure><img src="/files/QWjexuLGCYVTB8oC9EfZ" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can make changes to the worker, route, environment and more by clicking **Edit**, without the need to re-deploy the worker via wrangler.
{% endhint %}

Deployments of each worker can be seen by clicking on the Worker(e.g. test-netacea-worker) and selecting the Deployment's tab:

<figure><img src="/files/PALbyyIUDj8AncHb6UqS" alt=""><figcaption></figcaption></figure>

For each worker, you can see various metrics, the associated routes and have the option to roll-back to a previous deployment.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.netacea.com/netacea-plugin-information/cloudflare/installation-and-configuration/installation-via-wrangler-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
