Node.js & Express

1. Backend Integration

Add the Control API as middleware in your backend to scan all incoming requests.

Example with Node.js & Express

const express = require("express");
const fetch = require("node-fetch");
const app = express();

app.use(express.json());

// Middleware for Control API
app.use(async (req, res, next) => {
    const securityToken = req.headers["x-security-token"] || "";

    try {
        const response = await fetch("https://app.qubeguard.com/control", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "x-api-key": "YOUR_API_KEY", // Replace with your API key
                "x-security-token": securityToken,

            },
            body: JSON.stringify(req.body),
        });

        const result = await response.json();

        if (response.status !== 200 || result.error) {
            return res.status(403).json({ error: "Request blocked by Control API" });
        }

        next(); // Proceed to the next middleware/route
    } catch (error) {
        console.error("Control API error:", error);
        return res.status(500).json({ error: "Internal server error" });
    }
});

// Example route
app.post("/example", (req, res) => {
    res.status(200).json({ message: "Request passed successfully!" });
});

app.listen(3000, () => console.log("Server running on port 3000"));

Last updated