-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (48 loc) · 1.84 KB
/
index.js
File metadata and controls
59 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require("express");
const fetch = require("node-fetch"); // node-fetch v2 compatible con Node 16
const cors = require("cors");
require("dotenv").config();
const app = express();
const PORT = 4000;
app.use(cors()); // Permite que React haga peticiones a este backend
app.use(express.json()); // Para parsear JSON
app.post("/api/generate", async (req, res) => {
console.log("📨 Payload recibido en el proxy:", req.body); // 👈 Agregá este log
try {
const response = await fetch("https://stablehorde.net/api/v2/generate/async", {
method: "POST",
headers: {
"Content-Type": "application/json",
"apikey": process.env.HORDE_API_KEY || "tu_api_key_aqui",
"client_agent": "MiApp/1.0",
},
body: JSON.stringify(req.body),
});
const data = await response.json();
console.log("📦 Respuesta desde Stable Horde:", data); // 👈 Agregá esto
res.status(response.status).json(data);
} catch (error) {
console.error("❌ Error llamando a Stable Horde:", error);
res.status(500).json({ error: "Error al generar imagen" });
}
});
app.get("/api/generate/status/:id", async (req, res) => {
try {
const { id } = req.params;
const response = await fetch(`https://stablehorde.net/api/v2/generate/status/${id}`, {
headers: {
"apikey": process.env.HORDE_API_KEY || "tu_api_key_aqui",
"client_agent": "MiApp/1.0",
},
});
const data = await response.json();
console.log("📦 Estado de generación:", data); // 👈 Agregá esto
res.status(response.status).json(data);
} catch (error) {
console.error("Error consultando estado en Stable Horde:", error);
res.status(500).json({ error: "Error al consultar estado" });
}
});
app.listen(PORT, () => {
console.log(`Proxy backend escuchando en http://localhost:${PORT}`);
});