Spaces:
Paused
Paused
const express = require('express'); | |
const axios = require('axios'); | |
const cors = require('cors'); | |
const https = require('https'); // httpsモジュールをインポート | |
const app = express(); | |
const port = 3000; | |
// CORSを有効にする | |
app.use(cors()); | |
// httpsAgentを使って証明書検証を無効にする | |
const agent = new https.Agent({ | |
rejectUnauthorized: false // SSL証明書の検証を無効にする | |
}); | |
// リクエストを受け取るエンドポイント | |
app.get('/', async (req, res) => { | |
try { | |
const url = req.query.url; // クエリパラメータでURLを受け取る | |
if (!url) { | |
return res.status(400).send('URL is required'); | |
} | |
// 実際のAPIリクエストを送信 | |
const response = await axios.get(url, { httpsAgent: agent }); // httpsAgentを渡す | |
// コンテンツタイプを text/html に設定 | |
res.set('Content-Type', 'text/html'); | |
// HTMLレスポンスをそのままクライアントに返す | |
res.status(response.status).send(response.data); | |
} catch (error) { | |
console.error(error); | |
res.status(500).send('Something went wrong'); | |
} | |
}); | |
// サーバーを起動 | |
app.listen(port, () => { | |
console.log(`CORS proxy server running at http://localhost:${port}`); | |
}); | |