addign
This commit is contained in:
22
server.js
22
server.js
@ -11,6 +11,25 @@ app.use(bodyParser.json());
|
||||
|
||||
// API Key validation middleware
|
||||
const validateApiKey = (req, res, next) => {
|
||||
const trustedIps = [
|
||||
"2600:1702:6f0a:3c00:d065:e1b4:ac3b:d889", // Cloudflare real IP
|
||||
"::1", // localhost IPv6
|
||||
"127.0.0.1", // localhost IPv4
|
||||
];
|
||||
|
||||
const cfIp = req.headers["cf-connecting-ip"];
|
||||
const forwardedIp = req.headers["x-forwarded-for"];
|
||||
const userAgent = req.headers["user-agent"];
|
||||
|
||||
const clientIp = cfIp || forwardedIp || req.ip;
|
||||
|
||||
console.log("🔐 Incoming IP:", clientIp);
|
||||
console.log("🧭 User-Agent:", userAgent);
|
||||
|
||||
if (trustedIps.includes(clientIp)) {
|
||||
return next(); // Skip API key check for trusted IPs
|
||||
}
|
||||
|
||||
const apiKey = req.headers["api-key"];
|
||||
const authHeader = req.headers["authorization"];
|
||||
|
||||
@ -42,10 +61,7 @@ app.get("/", (req, res) => {
|
||||
app.post("/api/generate/api/chat", validateApiKey, async (req, res) => {
|
||||
try {
|
||||
const { model, messages, system } = req.body;
|
||||
console.log(req.host);
|
||||
console.log(req.ip);
|
||||
console.log(req.headers);
|
||||
console.log(req.headers.origin);
|
||||
|
||||
const prompt = messages
|
||||
.map(
|
||||
|
Reference in New Issue
Block a user