This page is intentionally simple: it sends your image(s) to /api/regula/process
on your server. Your server calls Regula Document Reader Web API (cloud or on‑prem) with your license / token. This avoids browser CORS & keeps your secret keys safe.
Server endpoint expected: POST /api/regula/process
(see Node/Express snippet below). It should forward files to Regula /api/process
with your license/token and chosen scenario, then return the JSON response unchanged.
// server.js
import express from "express";
import multer from "multer";
import fetch from "node-fetch";
import FormData from "form-data";
const app = express();
const upload = multer();
// Configure these from environment variables
const REGULA_BASE = process.env.REGULA_BASE || "https://api.regulaforensics.com"; // or your on-prem URL
const REGULA_TOKEN = process.env.REGULA_TOKEN; // e.g. 'Bearer <token>' or 'X-Device-Token ...' depending on your plan
app.post("/api/regula/process", upload.array("files"), async (req, res) => {
try {
const scenario = req.query.scenario || "FullProcess";
const lang = req.query.lang || "en";
const fd = new FormData();
// Regula expects 'processParam' JSON and one or more 'file' parts
fd.append("processParam", JSON.stringify({ scenario, resultTypeOutput: ["Text", "Mrz", "Images"] , configure: { recognition: { languages: [lang] } }}));
for (const f of req.files) {
fd.append("file", f.buffer, { filename: f.originalname, contentType: f.mimetype });
}
const r = await fetch(`${REGULA_BASE}/api/process`, {
method: "POST",
headers: {
// Use whichever header your subscription requires
Authorization: REGULA_TOKEN || "",
// Or: 'X-Device-Token': REGULA_TOKEN
},
body: fd,
});
const buf = await r.arrayBuffer();
res.status(r.status).set("content-type", r.headers.get("content-type")||"application/json").send(Buffer.from(buf));
} catch (e) {
console.error(e);
res.status(500).json({ error: e.message });
}
});
app.listen(3000, () => console.log("Proxy listening on http://localhost:3000"));
⚠️ Exact headers (Authorization vs X-Device-Token) can differ by account type/license. Keep tokens on the server; never expose them in the browser.