File size: 1,276 Bytes
28a33d6
483c455
28a33d6
a25f704
28a33d6
 
 
 
a25f704
28a33d6
 
a25f704
bef7f37
a25f704
bef7f37
 
a25f704
96a0071
28a33d6
a25f704
 
28a33d6
 
 
 
a25f704
 
f3b7e6e
33b6452
 
 
 
 
28a33d6
 
a25f704
28a33d6
 
 
a25f704
28a33d6
 
33b6452
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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}`);
});