hod / server.js
Mrlongpro's picture
Update server.js
cf42ebf verified
import express from "express";
import fetch from "node-fetch";
const app = express();
const PORT = process.env.PORT || 7860;
// Proxy Google Sheet
app.get("/", async (req, res) => {
try {
const url =
"https://docs.google.com/spreadsheets/d/e/2PACX-1vQMORhUByI3JJiqJcKrIuMMFS_VG97aqIfb3qIpclL4s93CHflrtq1yggsWpUKLfIzIjZdwvxxjuw4G/pubhtml?widget=true&headers=false";
const response = await fetch(url);
let text = await response.text();
// ⚡ Loại bỏ mọi thẻ <script> Google thêm (ngăn chặn block iframe)
text = text.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "");
// ⚡ Chỉnh sửa base URL để giữ CSS/Style
text = text.replace(
/<head>/i,
`<head><base href="https://docs.google.com/">`
);
res.set("Content-Type", "text/html; charset=utf-8");
res.send(text);
} catch (err) {
res.status(500).send("Lỗi khi tải Google Sheet: " + err.message);
}
});
app.listen(PORT, "0.0.0.0", () => {
console.log(`🚀 Server chạy ở http://0.0.0.0:${PORT}`);
});