const express = require("express");
const fetch = require("node-fetch");
const app = express();
app.use(express.json());
app.use(async (req, res, next) => {
try {
const response = await fetch("https://QubeGuard.com/example", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "YOUR_API_KEY",
},
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();
} catch (error) {
console.error("Control API error:", error);
return res.status(500).json({ error: "Internal server error" });
}
});
app.post("/example", (req, res) => {
res.status(200).json({ message: "Request passed successfully!" });
});
app.listen(3000, () => console.log("Server running on port 3000"));