LogoLogo
  • Overview
    • Overview
    • Integration Modes
    • Minimum Required Dataset
    • Customer Service Desk
  • Netacea Plugin Information
    • Accessing Your Integration Settings
    • Akamai
      • Akamai Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
        • Proxy Property Configuration
        • EdgeWorker Installation
        • Property Configuration
          • Optional Integration Configuration
    • Cloudflare
      • Cloudflare Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
        • Installation via Wrangler (CLI)
        • Installation via Cloudflare UI
    • CloudFront
      • CloudFront Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
    • Fastly
      • Fastly Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
        • Advanced Configuration
        • Deployment via Terraform
    • Fastly Magento
      • Fastly/Magento Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
        • Advanced Configuration
    • F5
      • F5 Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
    • Vercel
      • Vercel Plugin Logic
      • Monitoring Configuration
      • Installation and Configuration
    • API Direct Integration
      • How to Build a Netacea Plugin
  • Netacea Data Sync
    • Data Sync
    • Recommendations
  • Captcha
    • reCAPTCHA User Journey
    • hCaptcha User Journey
    • Custom reCAPTCHA Page Guide
    • Custom hCaptcha Page Guide
Powered by GitBook

Copyright Netacea 2023

On this page
  • Prerequisites
  • Installation
  • Configure the Vercel Project
  • Middleware Setup
  • Deploy the project to Vercel
  1. Netacea Plugin Information
  2. Vercel

Installation and Configuration

The Netacea Vercel integration detects bot activity and performs mitigating actions in line with the client blocking strategy.

PreviousMonitoring ConfigurationNextAPI Direct Integration

Last updated 1 month ago

Prerequisites

To successfully integrate using Netacea, please ensure you have:

  1. Installed , (version 16.13.0 or higher) and on you machine.

  2. An active Vercel account with access to the edge middleware functionality.

  3. A “Paid” Vercel subscription, in order to avoid any issues with request-limits etc.

  4. An existing Vercel Project.

  5. Details of the relevant API and Secret keys, and a Kinesis endpoint - provided by Netacea.

Installation

Within your Vercel project, run:

npm i @netacea/vercel .

This will install Netacea package to your project.

Configure the Vercel Project

Within the project, create NetaceaConfig.json in the same directory as your middleware(described in the "Middleware Setup" section). Then update its contents to match the below:

{
"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.

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.

cookieEncryptionKey, netaceaCookieName and netaceaCaptchaCookieName variables are used to increase security by concealing Netacea's default cookie names and values from public view.

Middleware Setup

A middleware.ts should be created in root directory of your project, if not present already. The following code should be placed in the middleware.ts file:

import { NextRequest, NextResponse } from 'next/server'
import { waitUntil } from '@vercel/functions'
import * as netaceaConfig from './NetaceaConfig.json'
import NetaceaVercelIntegration from '@netacea/vercel'
import type { NetaceaVercelIntegrationArgs } from '@netacea/vercel'

let netaceaWorker: NetaceaVercelIntegration | undefined = undefined

export default async function middleware(req: NextRequest) {
  try {
    // Initialize Netacea worker
    if (netaceaWorker === undefined) {
      netaceaWorker = new NetaceaVercelIntegration(netaceaConfig as NetaceaVercelIntegrationArgs)
    }

    // Run Netacea integration
    const event = { request: req }
    const netaceaResult = await netaceaWorker.run(event, originRequest)

    // Asynchronously ingest the Netacea result, without adding latency to the request
    waitUntil(netaceaWorker.ingest(req, netaceaResult))

    return netaceaResult.response
  } catch (error) {
    console.error("Netacea Middleware Error:", error)
    return NextResponse.next()
  }
}

async function originRequest(request: Request): Promise<NextResponse> {
  return NextResponse.next({
    headers: request.headers
  })
}

Deploy the project to Vercel

To successfully deploy the project to Vercel, the following steps must be followed:

  • Commit NetaceaConfig.json to your source control

  • Add NetaceaConfig.json to your .gitignore

  • The project should then be pushed to your Git repository.

Vercel will automatically detect the push to Github and initiate the deployment process.

Vercel command-line interface (CLI)
Node.js
Git