-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (37 loc) · 1.42 KB
/
server.js
File metadata and controls
45 lines (37 loc) · 1.42 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
const express = require("express");
const path = require("path");
const cors = require("cors");
const axios = require("axios");
const app = express();
const PORT = 3000;
// Enable CORS for all routes
app.use(cors({ origin: "*" }));
// Serve static images from the public folder
app.use("/public", express.static(path.join(__dirname, "public")));
// Proxy API route to fetch PageRank
app.get("/api/rank", async (req, res) => {
const site = req.query.url?.trim();
if (!site) return res.status(400).json({ error: "No website provided!" });
try {
const response = await axios.get(
`https://openpagerank.com/api/v1.0/getPageRank?domains[]=${site}`,
{ headers: { "API-OPR": "kw4wgkkow0skk4ccc8ko4kso4g0oggokokkswgws" } }
);
if (response.data && response.data.response?.length > 0) {
return res.json(response.data);
} else {
return res.status(404).json({ error: "No data found for this website." });
}
} catch (error) {
console.error("API Error:", error.response?.data || error.message);
res.status(500).json({ error: "Failed to fetch data", details: error.response?.data || error.message });
}
});
// Serve index.html correctly
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
// Start the server
app.listen(PORT, () => {
console.log(`✅ Server running at http://localhost:${PORT}`);
});