@adaptive-recognition/vehicle-detector-agent-webhook-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Vehicle Detector Agent Webhook Middleware

Express middleware for parsing Vehicle Detector Agent webhook requests and verifying their signature.

How to Install

npm install --save @arcloud/vehicle-detector-agent-webhook-middleware

Usage

TypeScript

import express, { Express, Request, Response } from 'express';
import { WebhookEvent, webhookSignatureValidator } from "@arcloud/vehicle-detector-agent-webhook-middleware";

const app: Express = express();
const port = 8080;

const signatureValidator = webhookSignatureValidator({
  algorithm: "RS256",
  publicKeyPath: "/path/to/RS256.public.pem"
});

app.get('/', (req: Request, res: Response) => {
  res.send('OK');
});

// This endpoint uses the middleware - requests with an invalid signature 
// will be rejected.
app.post('/webhook', signatureValidator, (req: Request, res: Response) => {
  const event: WebhookEvent = req.body; // req.body contains the parsed event
  console.log("Detected At: ", event.detectedAt);
  console.log("Unicode Text:", event.event.plate.unicodeText);
  res.send('OK');
});

app.listen(port, () => {
  console.log(`⚡️[server]: Server is running at https://localhost:${port}`);
});

JavaScript

const express = require("express");
const { webhookSignatureValidator } = require("@arcloud/vehicle-detector-agent-webhook-middleware");

const app = express();
const port = 8080;

const signatureValidator = webhookSignatureValidator({
  algorithm: "RS256",
  publicKeyPath: "/path/to/RS256.public.pem"
});

// This endpoint uses the middleware - requests with an invalid signature 
// will be rejected.
app.post('/webhook', signatureValidator, (req, res) => {
  const event = req.body; // req.body contains the parsed event
  console.log("Detected At: ", event.detectedAt);
  console.log("Unicode Text:", event.event.plate.unicodeText);
  res.send('OK');
});

app.listen(port, () => {
  console.log(`⚡️[server]: Server is running at https://localhost:${port}`);
});

Package Sidebar

Install

npm i @adaptive-recognition/vehicle-detector-agent-webhook-middleware

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

21.2 kB

Total Files

9

Last publish

Collaborators

  • laszlo.toth
  • botond.balazs.ar
  • tothl74