Update server.js
Browse files
server.js
CHANGED
|
@@ -4,27 +4,31 @@ import fetch from "node-fetch";
|
|
| 4 |
const app = express();
|
| 5 |
const PORT = process.env.PORT || 7860;
|
| 6 |
|
| 7 |
-
// Route gốc
|
| 8 |
-
app.get("/", (req, res) => {
|
| 9 |
-
res.send("✅ Node.js server chạy trên Hugging Face Space!");
|
| 10 |
-
});
|
| 11 |
-
|
| 12 |
// Proxy Google Sheet
|
| 13 |
app.get("/", async (req, res) => {
|
| 14 |
try {
|
| 15 |
const url =
|
| 16 |
-
"https://docs.google.com/spreadsheets/d/e/2PACX-1vQMORhUByI3JJiqJcKrIuMMFS_VG97aqIfb3qIpclL4s93CHflrtq1yggsWpUKLfIzIjZdwvxxjuw4G/pubhtml";
|
| 17 |
|
| 18 |
const response = await fetch(url);
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
res.set("Content-Type", "text/html");
|
| 22 |
res.send(text);
|
| 23 |
} catch (err) {
|
| 24 |
res.status(500).send("Lỗi khi tải Google Sheet: " + err.message);
|
| 25 |
}
|
| 26 |
});
|
| 27 |
|
| 28 |
-
app.listen(PORT, () => {
|
| 29 |
console.log(`🚀 Server chạy ở http://0.0.0.0:${PORT}`);
|
| 30 |
});
|
|
|
|
| 4 |
const app = express();
|
| 5 |
const PORT = process.env.PORT || 7860;
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
// Proxy Google Sheet
|
| 8 |
app.get("/", async (req, res) => {
|
| 9 |
try {
|
| 10 |
const url =
|
| 11 |
+
"https://docs.google.com/spreadsheets/d/e/2PACX-1vQMORhUByI3JJiqJcKrIuMMFS_VG97aqIfb3qIpclL4s93CHflrtq1yggsWpUKLfIzIjZdwvxxjuw4G/pubhtml?widget=true&headers=false";
|
| 12 |
|
| 13 |
const response = await fetch(url);
|
| 14 |
+
let text = await response.text();
|
| 15 |
+
|
| 16 |
+
// ⚡ Loại bỏ mọi thẻ <script> Google thêm (ngăn chặn block iframe)
|
| 17 |
+
text = text.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "");
|
| 18 |
+
|
| 19 |
+
// ⚡ Chỉnh sửa base URL để giữ CSS/Style
|
| 20 |
+
text = text.replace(
|
| 21 |
+
/<head>/i,
|
| 22 |
+
`<head><base href="https://docs.google.com/">`
|
| 23 |
+
);
|
| 24 |
|
| 25 |
+
res.set("Content-Type", "text/html; charset=utf-8");
|
| 26 |
res.send(text);
|
| 27 |
} catch (err) {
|
| 28 |
res.status(500).send("Lỗi khi tải Google Sheet: " + err.message);
|
| 29 |
}
|
| 30 |
});
|
| 31 |
|
| 32 |
+
app.listen(PORT, "0.0.0.0", () => {
|
| 33 |
console.log(`🚀 Server chạy ở http://0.0.0.0:${PORT}`);
|
| 34 |
});
|