自己ホスト推奨 — シンプルな Node.js 中継サーバー
以下はとても簡易な中継(開発用)。本番では認可・認証・ログ保護・TLS を必ず導入してください。
// server.js (Node.js) — save and run with: node server.js
// npm install express node-fetch cors
const express = require('express');
const fetch = require('node-fetch');
const cors = require('cors');
const app = express();
app.use(cors());
app.get('/fetch', async (req, res) => {
const url = req.query.url;
if (!url) return res.status(400).send('missing url');
try {
const resp = await fetch(url, { redirect: 'follow', compress: true, timeout: 20000 });
const contentType = resp.headers.get('content-type') || 'text/plain';
// pass-through for text/html and others; for privacy we strip some headers
res.set('content-type', contentType);
// Remove or override headers that might leak server info
res.removeHeader('x-powered-by');
// Stream the body:
const body = await resp.buffer();
res.send(body);
} catch (err) {
console.error('fetch error', err);
res.status(500).send('fetch error: ' + String(err));
}
});
const port = process.env.PORT || 3000;
app.listen(port, ()=>console.log('proxy running on http://localhost:' + port));
注意: 上は教育用の超簡易プロキシ。実運用では CSP、レート制御、認証、HTTPS、ログ制御、キャッシュ、ヘッダ除去、TLS強制を必ず実装してください。