Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from "express";
|
| 2 |
+
import axios from "axios";
|
| 3 |
+
import cors from "cors";
|
| 4 |
+
import bodyParser from "body-parser";
|
| 5 |
+
|
| 6 |
+
const app = express();
|
| 7 |
+
app.use(cors());
|
| 8 |
+
app.use(bodyParser.json());
|
| 9 |
+
|
| 10 |
+
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
|
| 11 |
+
const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY;
|
| 12 |
+
|
| 13 |
+
app.post("/lovable", async (req, res) => {
|
| 14 |
+
try {
|
| 15 |
+
const { prompt } = req.body;
|
| 16 |
+
|
| 17 |
+
// Fetch internet data via Firecrawl
|
| 18 |
+
const crawl = await axios.post(
|
| 19 |
+
"https://api.firecrawl.dev/v1/scrape",
|
| 20 |
+
{ prompt },
|
| 21 |
+
{ headers: { Authorization: `Bearer ${FIRECRAWL_API_KEY}` } }
|
| 22 |
+
);
|
| 23 |
+
|
| 24 |
+
// Send analysis + AI response via Gemini
|
| 25 |
+
const gemini = await axios.post(
|
| 26 |
+
"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=" + GEMINI_API_KEY,
|
| 27 |
+
{
|
| 28 |
+
contents: [{
|
| 29 |
+
parts: [{ text: prompt + "\n\nWeb Data:\n" + JSON.stringify(crawl.data) }]
|
| 30 |
+
}]
|
| 31 |
+
}
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
res.json({ reply: gemini.data.candidates[0].outputText });
|
| 35 |
+
} catch (e) {
|
| 36 |
+
res.json({ error: e.message });
|
| 37 |
+
}
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
app.get("/", (req, res) => {
|
| 41 |
+
res.send("🚀 Open-Lovable HF Space is Running");
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
app.listen(7860, () => console.log("Server running on 7860"));
|