-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
90 lines (78 loc) · 2.81 KB
/
server.ts
File metadata and controls
90 lines (78 loc) · 2.81 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import express from "express";
import { createServer as createViteServer } from "vite";
import path from "path";
import { GoogleGenAI, Type } from "@google/genai";
async function startServer() {
const app = express();
const PORT = 3000;
app.use(express.json());
// API Route for Crypto Analysis
app.post("/api/analyze", async (req, res) => {
const { url } = req.body;
if (!url) {
return res.status(400).json({ error: "URL is required" });
}
try {
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const prompt = `
Analyze the crypto project at this URL: ${url}
Provide a structured analysis with the following sections:
- Project Summary: A high-level overview.
- What it does: Detailed core functionality.
- Token Utility: How the token is used in the ecosystem.
- Potential Risks: Any red flags or market risks.
- Pros: Strong points of the project.
- Cons: Weaknesses or missing features.
- Risk Rating: Low, Medium, or High.
Return the response in a clean JSON format.
`;
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: prompt,
config: {
tools: [{ urlContext: {} }],
responseMimeType: "application/json",
responseSchema: {
type: Type.OBJECT,
properties: {
summary: { type: Type.STRING },
functionality: { type: Type.STRING },
utility: { type: Type.STRING },
risks: { type: Type.STRING },
pros: { type: Type.ARRAY, items: { type: Type.STRING } },
cons: { type: Type.ARRAY, items: { type: Type.STRING } },
rating: {
type: Type.STRING,
enum: ["Low", "Medium", "High"]
}
},
required: ["summary", "functionality", "utility", "risks", "pros", "cons", "rating"]
}
},
});
const result = JSON.parse(response.text || "{}");
res.json(result);
} catch (error) {
console.error("Gemini Error:", error);
res.status(500).json({ error: "Failed to analyze project. Please check the URL and try again." });
}
});
// Vite middleware for development
if (process.env.NODE_ENV !== "production") {
const vite = await createViteServer({
server: { middlewareMode: true },
appType: "spa",
});
app.use(vite.middlewares);
} else {
const distPath = path.join(process.cwd(), "dist");
app.use(express.static(distPath));
app.get("*", (req, res) => {
res.sendFile(path.join(distPath, "index.html"));
});
}
app.listen(PORT, "0.0.0.0", () => {
console.log(`Server running on http://localhost:${PORT}`);
});
}
startServer();