A piece of middlware for use with Express to connect to the Verified Visitors Access control app.
This middleware satisfies the api-integration documentation by making the correct requests to visitor access control and setting the correct response status, headers, and values. If you follow the below instructions, you will be ready to go.
To instantiate the middleware, you will need to provide the following parameters:
- an api token generated from the profile settings page.
- the application host, eg. example.verifiedvisitors.com. This must match the domain name set up in the VerifiedVisitors portal.
- an object containing
-
protocol
, this defaults to using the protocol from the request, but you may provide another protocol -
port
, an integer value representing the port your application runs on, defaults to null
-
An example:
import VacVerify from '@verifiedvisitors/integration-node'
const vvInstance = new VacVerify(VV_TOKEN, APPLICATION_HOST, {
port: 8080,
protocol: 'http',
})
server.use(vvInstance.middleware)
This implementation requires you to use the js code snippet in the HTML of the page your application serves to.
Please see our documentaion on installing this in the head of your html.
Once you have implemented the above, your site should be connected to visitor access control. To see this working, simply check the cookies on the relevant site to see a vv_vid
cookie.
You may add event listeners to the following events we emit:
-
allow
,block
, andcaptcha
- provides therequest
andresponse
objects to a callback you assign. -
error
- provides the error object to a callback you assign
An example:
import VacVerify from '@verified-visitors/express-integration'
import { type Request, type Response } from 'express'
const vvInstance = new VacVerify(VV_TOKEN, APPLICATION_HOST, { port: 8080, protocol: 'http' })
.on('block',
(request: Request, response: Response) =>
console.log(`Blocked ip: ${request.ip} from accessing ${request.url}. Returned ${response.statusCode}`)
)
.on('error', e: Error => console.error(`Error caught: ${e}`))
server.use(vvInstance.middleware)