Cloudflare Agent
Overview
Seamlessly integrated with NetFUNNEL in the Cloudflare Workers environment, the agent controls the queue in real time at the frontline where user requests originate.
Worker Environment Setup
Setting up the Cloudflare Workers environment with reference to Cloudflare's official documentation should be your first step.
After reviewing Cloudflare's official Workers guide, configure the Workers environment according to the guide.
Create and Configure Worker
Create Worker
- Go to [Workers and Pages].
- Under Workers, click [Create].
- Click [Hello world].
- Deploy to add.
Apply Agent to Worker
- Click [Edit code] at the top right.
- Prepare the agent file you downloaded through your inquiry.
- In the code editor, click [Explore] in the left tab to show the file list.
- Add the agent file.
- Open worker.js and add the following code.
import handleEvent from './{AGENT_FILE_NAME}'
export default {
async fetch(request, env, ctx) {
return await handleEvent(request, env, ctx);
},
};
- Click the [Deploy] button at the top right to deploy the Worker.
Worker Configuration
- Select the Worker you created and go to the [Settings] menu.
- Under Domains and routes, click [+ Add].
- Click [Route].
- In [Zone], select the domain and enter in [Route] the domain where the Worker will run. (Add /* at the end so the Worker runs on subpages as well.)
- Select [Fail open].
- Click [Add route].
- Refer to the table below to add variables and secrets.
You can find CLIENT_ID in the NetFUNNEL console.
| Type | Name | Value |
|---|---|---|
| Text | CLIENT_ID | CLIENT_ID |
- After adding the variable, click [Deploy].
Domain Configuration
Configure the domain set in section 3.2 as a CNAME so that requests to that path are handled by the Worker.
You must set the Proxy type.
Additional Features
Good Bot Exception
When the User-Agent contains a Good Bot identifier keyword, the request is excluded from agent control.
Worker Configuration
- In [Workers and Pages], select the Worker with the agent applied and go to the [Settings] tab.
- Add environment variables under Variables and secrets as shown in the table below.
Example of excluding Google, Microsoft, Yahoo, Apple, and Facebook bots.
| Type | Name | Value |
|---|---|---|
| Text | GOOD_BOTS | Googlebot, Bingbot, Slurp, Applebot, facebookexternalhit |
- After adding, click [Deploy].
Entry Key Auto-Return
The NetFUNNEL agent automatically returns the issued key after entry so the next user in line can enter. Use this feature when you want the key to be returned at the segment timeout instead of returning it immediately.
Worker Configuration
- In [Workers and Pages], select the Worker with the agent applied and go to the [Settings] tab.
- Refer to the table below to add environment variables under Variables and secrets.
| Type | Name | Value |
|---|---|---|
| Text | RETURN_KEY | true |
When set to true (default), the agent automatically returns the NetFUNNEL key when the user enters after waiting. When set to false, the key is returned at the timeout configured in the segment.
- After adding, click [Deploy].
Change Waiting Room Domain
The domain of the NetFUNNEL waiting room page is agent-lib.stclab.com. To change it to your service domain, request your desired domain and also add it to the configuration.
Worker Configuration
- In [Workers and Pages], select the Worker with the agent applied and go to the [Settings] tab.
- Add environment variables under Variables and secrets as shown in the table below.
| Type | Name | Value |
|---|---|---|
| Text | VWR_PAGE_DOMAIN | http(s)://{CNAME_DOMAIN} e.g. https://wait.stclab.com |
- After adding, click [Deploy].
Cookie Domain Configuration
The NetFUNNEL agent stores the issued key in cookies based on the current page domain after entry. To share keys across different subdomains, configure the main domain to be stored in the cookie.
Set to .stclab.com so that cookies are shared across pages with different subdomains, such as netfunnel.stclab.com and botmanager.stclab.com.
Worker Configuration
- In [Workers and Pages], select the Worker with the agent applied and go to the [Settings] tab.
- Add environment variables under Variables and secrets as shown in the table below.
| Type | Name | Value |
|---|---|---|
| Text | COOKIE_DOMAIN | .{MAIN_DOMAIN} e.g. .stclab.com |
- After adding, click [Deploy].