import express from "express"; import fetch from "node-fetch"; // html.cafeでは fetch が標準の場合もあり import cors from "cors"; const app = express(); const PORT = 3000; // ブラウザからアクセスできるようにCORS許可 app.use(cors()); // ルートでフロントページを返す app.get("/", (req, res) => { res.send(` 簡易ウェブプロキシ

簡易ウェブプロキシ

URLを入力して「表示」を押すと iframe 内に読み込みます

`); }); // /proxy でサーバー側プロキシ処理 app.get("/proxy", async (req, res) => { const targetUrl = req.query.url; if (!targetUrl) return res.status(400).send("urlパラメータが必要です"); try { const response = await fetch(targetUrl, { headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", }, }); const contentType = response.headers.get("content-type") || "text/html"; res.setHeader("Content-Type", contentType); const body = await response.text(); res.send(body); } catch (err) { res.status(500).send("プロキシ失敗: " + err.message); } }); app.listen(PORT, () => { console.log(\`プロキシサーバー起動: http://localhost:\${PORT}\`); });