Configuration

Basic Configuration

To use PerimeterX middleware on a specific route follow this example:

"use strict";

const express = require('express');
const perimeterx = require('perimeterx-node-express');

const server = express();

/* px-module and cookie parser need to be initiated before any route usage */
const pxConfig = {
    px_app_id: 'PX_APP_ID',
    px_cookie_secret: 'PX_COOKIE_SECRET',
    px_auth_token: 'PX_AUTH_TOKEN'
};
perimeterx.init(pxConfig);

/*  block users with high bot scores using px-module for the route /helloWorld */
server.get('/helloWorld', perimeterx.middleware, (req, res) => {
    res.send('Hello from PX');
});

server.listen(8081, () => {
    console.log('server started');
});
  • The PerimeterX Application ID / AppId and PerimeterX Token / Auth Token can be found in the Portal, in Applications.

  • The PerimeterX Cookie Encryption Key can be found in the portal, in Policies

The Policy from where the Cookie Encryption Key is taken must correspond with the Application from where the Application ID / AppId and PerimeterX Token / Auth Token

Setting the PerimeterX Middleware on all Server Routes

When configuring the PerimeterX middleware on all the server's routes, you will have a score evaluation on each incoming request. The recommended pattern is to use on top of page views routes.

"use strict";

const express = require('express');
const perimeterx = require('perimeterx-node-express');

const server = express();

/* the px-module and parser need to be initialized before any route usage */
const pxConfig = {
    px_app_id: 'PX_APP_ID',
    px_cookie_secret: 'PX_COOKIE_SECRET',
    px_auth_token: 'PX_AUTH_TOKEN'
};
perimeterx.init(pxConfig);

/* block high scored users using px-module for all routes */
server.use(perimeterx.middleware);

server.get('/helloWorld', (req, res) => {
    res.send('Hello from PX');
});

server.listen(8081, () => {
    console.log('server started');
});

Did this page help you?