| | const express = require("express"); |
| | const fetch = require("node-fetch"); |
| | const path = require("path"); |
| |
|
| | const app = express(); |
| |
|
| | const PORT = process.env.PORT || 7860; |
| | const TARGET = process.env.TARGET_API_URL; |
| |
|
| | if (!TARGET) { |
| | console.error("❌ 必须设置环境变量 TARGET_API_URL"); |
| | process.exit(1); |
| | } |
| |
|
| | |
| | app.use(express.static(path.join(__dirname, "public"))); |
| |
|
| | |
| | app.get("/api/data", async (req, res) => { |
| | try { |
| | const r = await fetch(TARGET, { |
| | headers: { |
| | "pragma": "no-cache" |
| | } |
| | }); |
| |
|
| | const text = await r.text(); |
| |
|
| | |
| | res.set("Access-Control-Allow-Origin", "*"); |
| | res.set("Content-Type", "application/json"); |
| |
|
| | res.send(text); |
| | } catch (e) { |
| | res.status(500).json({ error: e.toString() }); |
| | } |
| | }); |
| |
|
| | app.listen(PORT, () => { |
| | console.log("✅ Server running on port", PORT); |
| | }); |
| |
|